add log suppression tool
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
e76e604771
commit
5df7443437
2 changed files with 40 additions and 0 deletions
|
@ -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
38
src/core/log/suppress.rs
Normal 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");
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue