diff --git a/tracing-subscriber/src/reload.rs b/tracing-subscriber/src/reload.rs index 361234649b..72f5caff62 100644 --- a/tracing-subscriber/src/reload.rs +++ b/tracing-subscriber/src/reload.rs @@ -162,6 +162,16 @@ impl Handle { drop(lock); callsite::rebuild_interest_cache(); + + // If the `log` crate compatibility feature is in use, set `log`'s max + // level as well, in case the max `tracing` level changed. We do this + // *after* rebuilding the interest cache, as that's when the `tracing` + // max level filter is re-computed. + #[cfg(feature = "tracing-log")] + tracing_log::log::set_max_level(tracing_log::AsLog::as_log( + &crate::filter::LevelFilter::current(), + )); + Ok(()) } diff --git a/tracing-subscriber/tests/reload_max_log_level.rs b/tracing-subscriber/tests/reload_max_log_level.rs new file mode 100644 index 0000000000..5b870a918b --- /dev/null +++ b/tracing-subscriber/tests/reload_max_log_level.rs @@ -0,0 +1,36 @@ +mod support; +use self::support::*; +use tracing::{self, Level}; +use tracing_subscriber::{filter::LevelFilter, prelude::*, reload}; + +#[test] +fn reload_max_log_level() { + let (collector, finished) = collector::mock() + .event(event::mock().at_level(Level::INFO)) + .event(event::mock().at_level(Level::DEBUG)) + .event(event::mock().at_level(Level::INFO)) + .done() + .run_with_handle(); + let (filter, reload_handle) = reload::Subscriber::new(LevelFilter::INFO); + collector.with(filter).init(); + + assert!(log::log_enabled!(log::Level::Info)); + assert!(!log::log_enabled!(log::Level::Debug)); + assert!(!log::log_enabled!(log::Level::Trace)); + + log::debug!("i'm disabled"); + log::info!("i'm enabled"); + + reload_handle + .reload(Level::DEBUG) + .expect("reloading succeeds"); + + assert!(log::log_enabled!(log::Level::Info)); + assert!(log::log_enabled!(log::Level::Debug)); + assert!(!log::log_enabled!(log::Level::Trace)); + + log::debug!("i'm enabled now"); + log::info!("i'm still enabled, too"); + + finished.assert_finished(); +}