chiark / gitweb /
syslog: prep for printing level: Rename LogWrapper
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 24 Sep 2022 18:04:58 +0000 (19:04 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 25 Sep 2022 11:06:33 +0000 (12:06 +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 49c26a2f5fbced321209b31eed66494b94fb0e63..63780ebc1d224eac7f07dbde09f36d642b06d332 100644 (file)
@@ -29,9 +29,11 @@ fn parse_syslog_facility(s: &str) -> syslog::Facility {
 }
 
 #[derive(Debug)]
-struct FilteringLogWrapper<T>(T);
+struct LogWrapper<T>{
+  output: T,
+}
 
-impl<T> FilteringLogWrapper<T> {
+impl<T> LogWrapper<T> {
   fn wanted(&self, md: &log::Metadata<'_>) -> bool {
     let first = |mod_path| {
       let mod_path: &str = mod_path; // can't do in args as breaks lifetimes
@@ -41,19 +43,19 @@ impl<T> FilteringLogWrapper<T> {
   }
 }
 
-impl<T> log::Log for FilteringLogWrapper<T> where T: log::Log {
+impl<T> log::Log for LogWrapper<T> where T: log::Log {
   fn enabled(&self, md: &log::Metadata<'_>) -> bool {
-    self.wanted(md) && self.0.enabled(md)
+    self.wanted(md) && self.output.enabled(md)
   }
 
   fn log(&self, record: &log::Record<'_>) {
     if self.wanted(record.metadata()) {
-      self.0.log(record)
+      self.output.log(record)
     }
   }
 
   fn flush(&self) {
-    self.0.flush()
+    self.output.flush()
   }
 }
 
@@ -74,7 +76,7 @@ impl LogOpts {
         .context("set up syslog logger")?;
       let l = syslog::BasicLogger::new(l);
       let l = if self.debug < 2 {
-        Box::new(FilteringLogWrapper(l)) as _
+        Box::new(LogWrapper { output: l }) as _
       } else {
         Box::new(l) as _
       };