From 65d4ee1fe20fd5f77d296f2ff7217cff0b85fe72 Mon Sep 17 00:00:00 2001 From: Foxinatel Date: Fri, 9 Aug 2024 21:35:13 +0100 Subject: [PATCH] Make failure to connect to journald a warning, not a hard error --- src/main.rs | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/src/main.rs b/src/main.rs index 11fe0db..636d88b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -44,17 +44,34 @@ async fn main() -> Result<()> { color_eyre::install().wrap_err("failed to install color_eyre error handler")?; let trace = tracing_subscriber::registry(); + let env_filter = EnvFilter::builder() + .with_default_directive(LevelFilter::INFO.into()) + .from_env_lossy(); + #[cfg(feature = "systemd")] - let trace = trace.with(tracing_journald::layer().wrap_err("failed to connect to journald")?); + if let Ok(journald) = tracing_journald::layer() { + trace + .with(journald) + .with(fmt::layer()) + .with(env_filter) + .try_init() + .wrap_err("failed to initialize logger")?; + } else { + trace + .with(fmt::layer()) + .with(env_filter) + .try_init() + .wrap_err("failed to initialize logger")?; + warn!("failed to connect to journald") + } + + #[cfg(not(feature = "systemd"))] trace .with(fmt::layer()) - .with( - EnvFilter::builder() - .with_default_directive(LevelFilter::INFO.into()) - .from_env_lossy(), - ) + .with(env_filter) .try_init() .wrap_err("failed to initialize logger")?; + log_panics::init(); let (session_tx, mut session_rx) = tokio::sync::mpsc::channel(10);