mirror of
https://github.com/girlbossceo/conduwuit.git
synced 2024-11-27 20:45:30 +00:00
add log suppression tool
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
e76e604771
commit
5df7443437
|
@ -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…
Reference in a new issue