Skip to content

Commit

Permalink
aardvark main: change error reporting
Browse files Browse the repository at this point in the history
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 containers/podman#19809

Signed-off-by: Paul Holzinger <[email protected]>
  • Loading branch information
Luap99 committed Oct 18, 2023
1 parent 03796d2 commit 3633db0
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -79,7 +77,7 @@ fn main() {
match result {
Ok(_) => {}
Err(err) => {
println!("{}", err);
eprintln!("aardvark-dns: {}", err);
std::process::exit(1);
}
}
Expand Down

0 comments on commit 3633db0

Please sign in to comment.