From 05fed64629cd90269bf7845ee44f54ab42a86c9a Mon Sep 17 00:00:00 2001 From: Valentin Haudiquet Date: Tue, 17 Nov 2026 12:46:16 +0100 Subject: [PATCH] cli: prefix and color warnings and errors in the log output The logger format printed every record as a bare message, so a warning read like a stray lowercase fragment and an error like plain progress output. WARN: and ERROR: prefixes, yellow and red on a terminal, bare when piped; the other levels keep the bare message, which progress lines read better without. --- src/main.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 908f1b8..8791547 100644 --- a/src/main.rs +++ b/src/main.rs @@ -195,7 +195,22 @@ fn main() { let logger = env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")) .format_timestamp(None) - .format(|buf, record| writeln!(buf, "{}", record.args())) + .format(|buf, record| { + let message = record.args().to_string(); + match record.level() { + // Warnings and errors carry their level, colored for a + // terminal (bare when piped); the other levels keep the + // bare message, progress lines read better without a + // prefix + log::Level::Warn => { + writeln!(buf, "{}", ansi_wrap("33", &format!("WARN: {message}"))) + } + log::Level::Error => { + writeln!(buf, "{}", ansi_wrap("31", &format!("ERROR: {message}"))) + } + _ => writeln!(buf, "{message}"), + } + }) .build(); let multi = indicatif::MultiProgress::new(); LogWrapper::new(multi.clone(), logger).try_init().unwrap();