logger loginformation response code example
Example 1: response logging
Response Logging
If you want to print the response body regardless of the
status code you can do:
get("/x").then().log().body() ..
This will print the response body regardless if an error occurred.
If you're only interested in printing the response body if an error
occur then you can use:
get("/x").then().log().ifError(). ..
You can also log all details in the response
including status line, headers and cookies:
get("/x").then().log().all(). ..
as well as only status line, headers or cookies:
get("/x").then().log().statusLine(). .. // Only log the status line
get("/x").then().log().headers(). .. // Only log the response headers
get("/x").then().log().cookies(). .. // Only log the response cookies
You can also configure to log the response
only if the status code matches some value:
get("/x").then().log().ifStatusCodeIsEqualTo(302). .. //
Only log if the status code is equal to 302
get("/x").then().log().ifStatusCodeMatches(matcher). .. //
Only log if the status code matches the supplied Hamcrest matcher
Example 2: from loguru import logger examples
import time
from loguru import logger
from tqdm import tqdm
logger.remove()
logger.add(lambda msg: tqdm.write(msg, end=""))
logger.info("Initializing")
for x in tqdm(range(100)):
logger.info("Iterating #{}", x)
time.sleep(0.1)