I'm not sure if this is an actual (software) bug, or just a case of an outdated documentation: The examples given in the documentation of tracing_subscriber::reload do not seem to work as described there.
Linux fabuntu 5.15.0-122-generic #132-Ubuntu SMP Thu Aug 29 13:45:52 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
Crates
tracing_subscriber
Description
I've copy/pasted the two examples given in the documentation into this standalone module, extended by a bit more debug output:
use log::{info, warn};
use tracing_subscriber::{filter, fmt, prelude::*, reload};
fn example_1() {
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)
.unwrap();
warn!("Test line before");
info!("This will be logged");
warn!("Test line after");
}
fn example_2() {
let filtered_layer = fmt::Layer::default().with_filter(filter::LevelFilter::WARN);
let (filtered_layer, reload_handle) = reload::Layer::new(filtered_layer);
tracing_subscriber::registry().with(filtered_layer).init();
info!("This will be ignored");
reload_handle
.modify(|layer| *layer.filter_mut() = filter::LevelFilter::INFO)
.unwrap();
warn!("Test line before");
info!("This will be logged");
warn!("Test line after");
}
fn main() {
example_1();
}
Running either example_1() or example_2() both result in the output:
2024-09-22T08:02:05.237190Z WARN debug_logging: Test line before
2024-09-22T08:02:05.237210Z WARN debug_logging: Test line after
I.e., both examples don't actually log the line info!("This will be logged"); as they suggest to do.
yes, this looks like a duplicate of #2711, which has already been fixed on master with #1270, but hasn't been backported for some reason. Note that it works with the tracing::info!, tracing::warn! macros.
Bug Report
I'm not sure if this is an actual (software) bug, or just a case of an outdated documentation: The examples given in the documentation of
tracing_subscriber::reload
do not seem to work as described there.Version
The
log
crate is 0.4.22.Platform
Linux fabuntu 5.15.0-122-generic #132-Ubuntu SMP Thu Aug 29 13:45:52 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
Crates
tracing_subscriber
Description
I've copy/pasted the two examples given in the documentation into this standalone module, extended by a bit more debug output:
Running either
example_1()
orexample_2()
both result in the output:I.e., both examples don't actually log the line
info!("This will be logged");
as they suggest to do.Possibly related to: