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
Subscriber
as the default. Thefmt::SubscriberBuilder::finish
method you're calling returns a newfmt::Subscriber
, but it doesn't actually configuretracing
to use thatSubscriber
to collect traces. Try passing the returnedfmt::Subscriber
totracing::subscriber::set_global_default
, or callSubscriberBuilder::init()
rather thanSubscriberBuilder::finish
(which callsset_global_default
for you), and then your code should work the way you expect.We should probably add
#[must_use]
annotations to either thefinish
method or thefmt::Subscriber
type, so that this code would have generated a warning telling you you're not using the returned subscriber...then, the proble…