add log suppression tool

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2024-06-13 02:15:51 +00:00
parent e76e604771
commit 5df7443437
2 changed files with 40 additions and 0 deletions

View file

@ -3,10 +3,12 @@ pub mod color;
pub mod fmt;
mod reload;
mod server;
mod suppress;
pub use capture::Capture;
pub use reload::{LogLevelReloadHandles, ReloadHandle};
pub use server::Server;
pub use suppress::Suppress;
pub use tracing::Level;
pub use tracing_core::{Event, Metadata};

38
src/core/log/suppress.rs Normal file
View file

@ -0,0 +1,38 @@
use std::sync::Arc;
use super::EnvFilter;
use crate::Server;
pub struct Suppress {
server: Arc<Server>,
restore: EnvFilter,
}
impl Suppress {
pub fn new(server: &Arc<Server>) -> Self {
let config = &server.config.log;
Self::from_filters(server, EnvFilter::try_new(config).unwrap_or_default(), &EnvFilter::default())
}
fn from_filters(server: &Arc<Server>, restore: EnvFilter, suppress: &EnvFilter) -> Self {
server
.log
.reload
.reload(suppress)
.expect("log filter reloaded");
Self {
server: server.clone(),
restore,
}
}
}
impl Drop for Suppress {
fn drop(&mut self) {
self.server
.log
.reload
.reload(&self.restore)
.expect("log filter reloaded");
}
}