reqwest icon indicating copy to clipboard operation
reqwest copied to clipboard

How to enable logging for all requests/responses

Open Masber opened this issue 3 years ago • 1 comments

Hi, I have a module with reqwest and eng_logger.

Is it possible to enable logging so reqwest uses log to to print all requests and responses? I would like to see the endpoint, headers, body, etc.

If this is possible, how?

thank you

Masber avatar Sep 18 '22 17:09 Masber

The only way to fully log all the data you're asking for is to also set the connection_verbose() Client builder option, and then enable logging.

seanmonstar avatar Sep 18 '22 18:09 seanmonstar

Just to show an example...

let client = reqwest::Client::builder().connection_verbose(true).build().unwrap();

Add env_logger to your Cargo.toml and enable it when your application starts...

async fn main() {
    env_logger::init();
    // ...
}

To enable maximum logging for reqwest, use trace level logging; e.g. start your application with:

RUST_LOG=reqwest=trace cargo run

xpe avatar Jan 11 '24 21:01 xpe