Why does setting the log level programmatically not work? with_max_level not working?
#2551
-
|
I'm trying for a while to set the log level programmatically. The very first lines of my tracing_subscriber::fmt::fmt()
.with_max_level(tracing::Level::DEBUG)
.compact()
.finish();
tracing::info!("Test info level");
tracing::debug!("Test debug level");I would have expected to see these traces on stdout, but there is nothing. Is this a bug or am I misunderstanding something here? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
You aren't setting the We should probably add |
Beta Was this translation helpful? Give feedback.
You aren't setting the
Subscriberas the default. Thefmt::SubscriberBuilder::finishmethod you're calling returns a newfmt::Subscriber, but it doesn't actually configuretracingto use thatSubscriberto collect traces. Try passing the returnedfmt::Subscribertotracing::subscriber::set_global_default, or callSubscriberBuilder::init()rather thanSubscriberBuilder::finish(which callsset_global_defaultfor you), and then your code should work the way you expect.We should probably add
#[must_use]annotations to either thefinishmethod or thefmt::Subscribertype, so that this code would have generated a warning telling you you're not using the returned subscriber...then, the proble…