From 10027551b359e315a81efa420c2ae41f26da4610 Mon Sep 17 00:00:00 2001 From: Caleb Etemesi Date: Sun, 9 Oct 2022 16:16:36 +0300 Subject: [PATCH] Ensure log levels are appropriately padded even on coloured outputs. --- src/lib.rs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 3033737..0a8816b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -375,19 +375,18 @@ impl Log for SimpleLogger { { if self.colors { match record.level() { - Level::Error => record.level().to_string().red().to_string(), - Level::Warn => record.level().to_string().yellow().to_string(), - Level::Info => record.level().to_string().cyan().to_string(), - Level::Debug => record.level().to_string().purple().to_string(), - Level::Trace => record.level().to_string().normal().to_string(), - } + Level::Error => format!("{:<5}",record.level().to_string()).red().to_string(), + Level::Warn => format!("{:<5}",record.level().to_string()).yellow().to_string(), + Level::Info => format!("{:<5}",record.level().to_string()).cyan().to_string(), + Level::Debug => format!("{:<5}",record.level().to_string()).purple().to_string(), + Level::Trace => format!("{:<5}",record.level().to_string()).normal().to_string(), } } else { - record.level().to_string() + format!("{:<5}", record.level().to_string()) } } #[cfg(not(feature = "colored"))] { - record.level().to_string() + format!("{:<5}", record.level().to_string()) } }; @@ -443,7 +442,7 @@ impl Log for SimpleLogger { }; let message = format!( - "{}{:<5} [{}{}] {}", + "{}{} [{}{}] {}", timestamp, level_string, target,