diff --git a/src/core/log/reload.rs b/src/core/log/reload.rs index 0b72d787..6d651065 100644 --- a/src/core/log/reload.rs +++ b/src/core/log/reload.rs @@ -22,10 +22,14 @@ use crate::{error, Result}; /// /// [1]: pub trait ReloadHandle { + fn current(&self) -> Option; + fn reload(&self, new_value: L) -> Result<(), reload::Error>; } -impl ReloadHandle for reload::Handle { +impl ReloadHandle for reload::Handle { + fn current(&self) -> Option { Self::clone_current(self) } + fn reload(&self, new_value: L) -> Result<(), reload::Error> { Self::reload(self, new_value) } } @@ -57,6 +61,15 @@ impl LogLevelReloadHandles { Ok(()) } + + #[must_use] + pub fn current(&self, name: &str) -> Option { + self.handles + .lock() + .expect("locked") + .get(name) + .map(|handle| handle.current())? + } } impl Default for LogLevelReloadHandles { diff --git a/src/core/log/suppress.rs b/src/core/log/suppress.rs index ca2d5485..b13ee99e 100644 --- a/src/core/log/suppress.rs +++ b/src/core/log/suppress.rs @@ -10,16 +10,21 @@ pub struct Suppress { impl Suppress { pub fn new(server: &Arc) -> Self { + let handle = "console"; let config = &server.config.log; - Self::from_filters(server, EnvFilter::try_new(config).unwrap_or_default(), &EnvFilter::default()) - } + let suppress = EnvFilter::default(); + let restore = server + .log + .reload + .current(handle) + .unwrap_or_else(|| EnvFilter::try_new(config).unwrap_or_default()); - fn from_filters(server: &Arc, restore: EnvFilter, suppress: &EnvFilter) -> Self { server .log .reload - .reload(suppress, Some(&["console"])) + .reload(&suppress, Some(&[handle])) .expect("log filter reloaded"); + Self { server: server.clone(), restore,