possible to adjust max log level on the fly #2121
-
Feature RequestMotivationas a developer I would like to adjust the log level on the fly, for example, I don't want to log debug log when everything is going fine, but when something happened, I would like to adjust the log level without restart the application by develop an control plane api to change the log level, I check the doc and can't find an example there. so I want to know if it is possible to do that. Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
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"); |
Beta Was this translation helpful? Give feedback.
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: