From 3633db0eaeeddfe02c2f754fbabf2a26afca4b81 Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Wed, 18 Oct 2023 15:00:50 +0200 Subject: [PATCH] aardvark main: change error reporting Never report an error when the syslog init fails, there are systems without syslog (e.g. inside containers) and we should not spam a random expected messages in this context. Also add aardvark-dns to the error context as this is printed to stderr which is inherited from the podman command so it is not clear which process wrote it otherwise. Fixes https://github.com/containers/podman/issues/19809 Signed-off-by: Paul Holzinger --- src/main.rs | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/main.rs b/src/main.rs index 52261338..c00f5349 100644 --- a/src/main.rs +++ b/src/main.rs @@ -44,24 +44,22 @@ fn main() { Ok(val) => match Level::from_str(&val) { Ok(level) => level, Err(e) => { - eprintln!("failed to parse RUST_LOG level: {}", e); + eprintln!("aardvark-dns: failed to parse RUST_LOG level: {}", e); Level::Info } }, + // if env is not set default to info Err(_) => Level::Info, }; - match syslog::unix(formatter) { - Ok(logger) => { - if let Err(e) = log::set_boxed_logger(Box::new(BasicLogger::new(logger))) - .map(|()| log::set_max_level(log_level.to_level_filter())) - { - eprintln!("failed to initialize syslog logger: {}", e) - }; - } - Err(e) => { - eprintln!("failed to connect to syslog: {}", e); - } + // On error do nothing, running on system without syslog is fine and we should not clutter + // logs with meaningless errors, https://github.com/containers/podman/issues/19809. + if let Ok(logger) = syslog::unix(formatter) { + if let Err(e) = log::set_boxed_logger(Box::new(BasicLogger::new(logger))) + .map(|()| log::set_max_level(log_level.to_level_filter())) + { + eprintln!("aardvark-dns: failed to initialize syslog logger: {}", e) + }; } let opts = Opts::parse(); @@ -79,7 +77,7 @@ fn main() { match result { Ok(_) => {} Err(err) => { - println!("{}", err); + eprintln!("aardvark-dns: {}", err); std::process::exit(1); } }