Skip to content

Commit

Permalink
Updated LogLevel and TextLogger formatting.
Browse files Browse the repository at this point in the history
  • Loading branch information
dousamichal0807 committed Apr 22, 2022
1 parent 6af4e43 commit 193279d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/level.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
})
Expand Down
13 changes: 6 additions & 7 deletions src/loggers/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)
}
}

0 comments on commit 193279d

Please sign in to comment.