Skip to content

Why does setting the log level programmatically not work? with_max_level not working? #2551

Answered by hawkw
bluenote10 asked this question in Q&A
Discussion options

You must be logged in to vote

You aren't setting the Subscriber as the default. The fmt::SubscriberBuilder::finish method you're calling returns a new fmt::Subscriber, but it doesn't actually configure tracing to use that Subscriber to collect traces. Try passing the returned fmt::Subscriber to tracing::subscriber::set_global_default, or call SubscriberBuilder::init() rather than SubscriberBuilder::finish (which calls set_global_default for you), and then your code should work the way you expect.

We should probably add #[must_use] annotations to either the finish method or the fmt::Subscriber type, so that this code would have generated a warning telling you you're not using the returned subscriber...then, the proble…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by bluenote10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants