Add option to not collect logs (#517)

There's currently no way for an app with a logger service to disable
log collection.
This commit is contained in:
Giacomo Pasini 2023-11-08 15:47:07 +01:00 committed by GitHub
parent c3422c196c
commit 3e1a722bd2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 0 deletions

View File

@ -68,6 +68,8 @@ pub enum LoggerBackend {
Stderr, Stderr,
#[serde(skip)] #[serde(skip)]
Writer(SharedWriter), Writer(SharedWriter),
// do not collect logs
None,
} }
#[derive(Clone, Debug, Serialize, Deserialize)] #[derive(Clone, Debug, Serialize, Deserialize)]
@ -158,6 +160,12 @@ impl ServiceCore for Logger {
LoggerBackend::Stdout => tracing_appender::non_blocking(std::io::stdout()), LoggerBackend::Stdout => tracing_appender::non_blocking(std::io::stdout()),
LoggerBackend::Stderr => tracing_appender::non_blocking(std::io::stderr()), LoggerBackend::Stderr => tracing_appender::non_blocking(std::io::stderr()),
LoggerBackend::Writer(writer) => tracing_appender::non_blocking(writer), LoggerBackend::Writer(writer) => tracing_appender::non_blocking(writer),
LoggerBackend::None => {
return Ok(Self {
service_state,
worker_guard: None,
})
}
}; };
let layer = tracing_subscriber::fmt::Layer::new() let layer = tracing_subscriber::fmt::Layer::new()