From 9082a396043547f0daab4dd096b9a6d95813a036 Mon Sep 17 00:00:00 2001 From: Lucas Nogueira Date: Fri, 23 Aug 2024 13:20:24 -0300 Subject: [PATCH] fix(cli): env_logger usage --- tooling/cli/src/lib.rs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/tooling/cli/src/lib.rs b/tooling/cli/src/lib.rs index ad41405c1414..a2e581ba60a2 100644 --- a/tooling/cli/src/lib.rs +++ b/tooling/cli/src/lib.rs @@ -16,7 +16,7 @@ mod plugin; mod signer; use clap::{ArgAction, CommandFactory, FromArgMatches, Parser, Subcommand}; -use env_logger::fmt::style::{AnsiColor, Style}; +use env_logger::fmt::Color; use env_logger::Builder; use log::{debug, log_enabled, Level}; use serde::Deserialize; @@ -132,23 +132,27 @@ where let action = action.to_cow_str().unwrap(); is_command_output = action == "stdout" || action == "stderr"; if !is_command_output { - let style = Style::new().fg_color(Some(AnsiColor::Green.into())).bold(); + let mut action_style = f.style(); + action_style.set_color(Color::Green).set_bold(true); - write!(f, " {style}{}{style:#} ", action)?; + write!(f, "{:>12} ", action_style.value(action))?; } } else { - let style = f.default_level_style(record.level()).bold(); + let mut level_style = f.default_level_style(record.level()); + level_style.set_bold(true); + write!( f, - " {style}{}{style:#} ", - prettyprint_level(record.level()) + "{:>12} ", + level_style.value(prettyprint_level(record.level())) )?; } if !is_command_output && log_enabled!(Level::Debug) { - let style = Style::new().fg_color(Some(AnsiColor::Black.into())); + let mut target_style = f.style(); + target_style.set_color(Color::Black); - write!(f, "[{style}{}{style:#}] ", record.target())?; + write!(f, "[{}] ", target_style.value(record.target()))?; } writeln!(f, "{}", record.args())