From 193279d3e71123c19459853ce6f350047045b5ee Mon Sep 17 00:00:00 2001 From: dousamichal0807 Date: Fri, 22 Apr 2022 15:33:15 +0200 Subject: [PATCH] Updated `LogLevel` and `TextLogger` formatting. --- src/level.rs | 4 ++-- src/loggers/text.rs | 13 ++++++------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/level.rs b/src/level.rs index 461fba0..9cf79ef 100644 --- a/src/level.rs +++ b/src/level.rs @@ -62,8 +62,8 @@ impl Display for LogLevel { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { write!(f, "{}", match self { Self::Debug => "DEBUG", - Self::Info => "INFO", - Self::Warning => "WARN", + Self::Info => "INFO ", + Self::Warning => "WARN ", Self::Error => "ERROR", Self::Fatal => "FATAL", }) diff --git a/src/loggers/text.rs b/src/loggers/text.rs index 796c38c..915f0d7 100644 --- a/src/loggers/text.rs +++ b/src/loggers/text.rs @@ -73,10 +73,7 @@ where /// - `min_log_level`: minimum log level /// - `writer`: an output stream the log is written into pub fn new(min_log_level: LogLevel, writer: W) -> Self { - Self { - min_log_level, - writer, - } + Self { min_log_level, writer } } /// Returns the minimum log level of the [`Logger`] instance. @@ -92,9 +89,11 @@ where fn log(&mut self, log_level: LogLevel, message: &str) -> io::Result<()> { // Do not do anything if log level is too low: if log_level < self.min_log_level { return Result::Ok(()) } + // Construct what to show as category: + let category = thread::current().name() + .map(|name| format!(" {}", name)) + .unwrap_or_default(); // Write to the specified stream: - writeln!(self.writer, "[{} {}]@{}: {}", - thread::current().name().unwrap_or(""), - log_level, Local::now(), message) + writeln!(self.writer, "{} [{} {}]: {}", Local::new(), log_level, category, message) } } \ No newline at end of file