Skip to content

Commit

Permalink
fix(cli): env_logger usage
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog committed Aug 23, 2024
1 parent d84ae44 commit 9082a39
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions tooling/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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())
Expand Down

0 comments on commit 9082a39

Please sign in to comment.