From: Ian Jackson Date: Sat, 24 Sep 2022 18:06:44 +0000 (+0100) Subject: syslog: prep for printing level: Move debug handling X-Git-Tag: hippotat/1.0.0~71 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=4d3fdbfdc98cc484fc1a116fd16c8d3f26f93f28;p=hippotat.git syslog: prep for printing level: Move debug handling We're going to want to add a note to every message. It makes sense to use the same wrapper struct and give it more of the functionality. Signed-off-by: Ian Jackson --- diff --git a/src/reporter.rs b/src/reporter.rs index 63780eb..0fdecd0 100644 --- a/src/reporter.rs +++ b/src/reporter.rs @@ -30,6 +30,7 @@ fn parse_syslog_facility(s: &str) -> syslog::Facility { #[derive(Debug)] struct LogWrapper{ + debug: usize, output: T, } @@ -39,7 +40,7 @@ impl LogWrapper { let mod_path: &str = mod_path; // can't do in args as breaks lifetimes mod_path.split_once("::").map(|s| s.0).unwrap_or(mod_path) }; - first(md.target()) == first(module_path!()) + self.debug >= 2 || first(md.target()) == first(module_path!()) } } @@ -75,11 +76,8 @@ impl LogOpts { .map_err(|e| anyhow!(e.to_string())) .context("set up syslog logger")?; let l = syslog::BasicLogger::new(l); - let l = if self.debug < 2 { - Box::new(LogWrapper { output: l }) as _ - } else { - Box::new(l) as _ - }; + let l = LogWrapper { output: l, debug: self.debug }; + let l = Box::new(l) as _; log::set_boxed_logger(l).context("install syslog logger")?; log::set_max_level(if self.debug < 1 { log::LevelFilter::Debug