From 445b22fecdd661dea7f9466f93a7324312720dcf Mon Sep 17 00:00:00 2001 From: Neshura Date: Tue, 26 Dec 2023 04:06:38 +0100 Subject: [PATCH] Conditional logging destination --- src/config.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/config.rs b/src/config.rs index 42d1cd8..8734b2d 100644 --- a/src/config.rs +++ b/src/config.rs @@ -16,7 +16,10 @@ impl InterfaceConfig { let cfg: Self = match confy::load(env!("CARGO_PKG_NAME"),"interfaces") { Ok(data) => data, Err(e) => { - error!("[ERROR] {}", e); + match connected_to_journal() { + true => error!("[ERROR] {e}"), + false => eprintln!("[ERROR] {e}") + } return Err(Box::new(e)); } }; @@ -75,7 +78,11 @@ impl ZoneConfig { let entry = entry?; let path = entry.path(); if path.is_dir() { - warn!("[WARN] Subdirectory in zones.d detected, this should not be the case"); + let warn_msg = "Subdirectory in zones.d detected, this should not be the case"; + match connected_to_journal() { + true => warn!("[WARN] {warn_msg}"), + false => eprintln!("[WARN] {warn_msg}"), + } } else { let zone_config_path = format!("zones.d/{}", path.file_stem() @@ -84,7 +91,10 @@ impl ZoneConfig { match confy::load(env!("CARGO_PKG_NAME"), zone_config_path.as_str()) { Ok(data) => zone_configs.push(data), Err(e) => { - error!("[ERROR] {}", e); + match connected_to_journal() { + true => error!("[ERROR] {e}"), + false => eprintln!("[ERROR] {e}"), + } return Err(Box::new(e)); } };