I have many dependencies and there are logs of some dependencies that I don't care, how can I exclude them?
you can use a Targets
filter. example:
let filter = filter::Targets::new()
// Enable the `INFO` level for anything in `my_crate`
.with_target("my_crate", Level::INFO)
// use `OFF` level filter for specific crate
.with_target("other_crate", LevelFilter::OFF);
// Build a new subscriber with the `fmt` layer using the `Targets`
// filter we constructed above.
tracing_subscriber::registry()
.with(tracing_subscriber::fmt::layer())
.with(filter)
.init();
3 Likes
Can I only set other_crates at OFF level and by default others are able to log?
You can use Targets::with_default
to define the default log level and then go about your business of finer-grained log level configuration.
If you want to use the EnvFilter
with the RUST_LOG
environment variable, I believe specifying RUST_LOG=info,other_crate=off
should do what you want.
1 Like