chiark / gitweb /
syslog: prep for printing level: Move debug handling
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 24 Sep 2022 18:06:44 +0000 (19:06 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 25 Sep 2022 11:07:04 +0000 (12:07 +0100)
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 <ijackson@chiark.greenend.org.uk>
src/reporter.rs

index 63780ebc1d224eac7f07dbde09f36d642b06d332..0fdecd08592ea9eb0086ff90f6895c726ec89526 100644 (file)
@@ -30,6 +30,7 @@ fn parse_syslog_facility(s: &str) -> syslog::Facility {
 
 #[derive(Debug)]
 struct LogWrapper<T>{
+  debug: usize,
   output: T,
 }
 
@@ -39,7 +40,7 @@ impl<T> LogWrapper<T> {
       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