2

I am a novice in rust. I try to use axum and the tracing framework to make a web program. When I use tracing and send requests, there will be hyper log output. How do I filter out these logs and keep the logs of my application itself?

mycode:


        let filter: EnvFilter = "hyper=debug".parse().expect("filter should parse");
        let logger = Registry::default()
            .with(EnvFilter::from_default_env().add_directive(log_env.into()).with_filter(filter))
            .with(fmt::Layer::default().event_format(format))
            ;

        tracing::subscriber::set_global_default(logger).unwrap();

but not work for me

fxdom
  • 21
  • 2
  • 1
    `hyper=debug` means that you want the traces at level `debug` or higher for `hyper`. If you want to disable them, you need to use a higher level, e.g. `hyper=error` to only see the errors. – Jmb Jun 06 '23 at 14:55

1 Answers1

0

in your Cargo.toml

tracing-subscriber = {version="0.3", features=["env-filter"]}

in your code:

tracing_subscriber::fmt::fmt()
        .with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
        .init();

then:

RUST_LOG=my_crate=DEBUG cargo run

exlinx
  • 19
  • 5