Hyper(tracing) logging in env_logger maner?

I use reqwest to make HTTP requests.
And I want to see what happens under the hood.
In my application I use env_logger.
And before for debugging I just ran:

RUST_LOG=reqwest=trace,hyper=trace ./myapp

But now I see only reqwest logs.
I look at hyper code, and looks like they switched to tracing crate. Any way to redirect tracing data to stdout, if take into consideration that I do not directly depend on hyper, only via reqwest?

1 Like

You must enable a Subscriber to do anything with the log messages created by tracing, like printing them to stdout. The tracing-subscriber crate provides a good Subscriber. Re-using the RUST_LOG environment variable and showing the hyper logs should be as easy as adding the following to your code:

Cargo.toml:

[dependencies]
tracing-subscriber = { version = "^0.3.16", features = ["env-filter"] }

main.rs:

fn main() {
    tracing_subscriber::fmt::init();
}

Here some more background:

4 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.