From ebb028ca6172b8bce03f2eb81607c77e412fdd22 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sat, 24 Sep 2022 19:04:58 +0100 Subject: [PATCH] syslog: prep for printing level: Rename LogWrapper 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 --- src/reporter.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/reporter.rs b/src/reporter.rs index 49c26a2..63780eb 100644 --- a/src/reporter.rs +++ b/src/reporter.rs @@ -29,9 +29,11 @@ fn parse_syslog_facility(s: &str) -> syslog::Facility { } #[derive(Debug)] -struct FilteringLogWrapper(T); +struct LogWrapper{ + output: T, +} -impl FilteringLogWrapper { +impl LogWrapper { 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 FilteringLogWrapper { } } -impl log::Log for FilteringLogWrapper where T: log::Log { +impl log::Log for LogWrapper 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 _ }; -- 2.30.2