Skip to content

possible to adjust max log level on the fly #2121

Answered by jswrenn
xujihui1985 asked this question in Q&A
Discussion options

You must be logged in to vote

I believe layer reloading is what you're looking for. The first example on that linked page demonstrates how to change the global filtering level on-the-fly:

use tracing_subscriber::{filter, fmt, reload, prelude::*};

let filter = filter::LevelFilter::WARN;
let (filter, reload_handle) = reload::Layer::new(filter);
tracing_subscriber::registry()
  .with(filter)
  .with(fmt::Layer::default())
  .init();

info!("This will be ignored");

reload_handle.modify(|filter| *filter = filter::LevelFilter::INFO);

info!("This will be logged");

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by hawkw
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
Converted from issue

This discussion was converted from issue #2111 on May 11, 2022 20:37.