Skip to content

Commit

Permalink
fix: logger formatting for new env_logger version
Browse files Browse the repository at this point in the history
  • Loading branch information
cestef committed Jan 2, 2025
1 parent 631ffe6 commit 9a90df6
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions src/utils/logger.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use env_logger::{fmt::Color, Builder, Env};
use env_logger::{fmt::style::AnsiColor as Color, Builder, Env};

use std::io::Write;

Expand All @@ -22,31 +22,36 @@ pub fn init_logger() {
.filter_module("rustyline::tty::unix", log::LevelFilter::Warn)
.filter_module("rustyline::tty::unix::termios_", log::LevelFilter::Warn)
.format(|buf, record| {
let mut style = buf.style();
match record.level() {
log::Level::Info => style.set_color(Color::Blue),
log::Level::Warn => style.set_color(Color::Yellow),
log::Level::Error => style.set_color(Color::Red),
log::Level::Debug => style.set_color(Color::Cyan),
log::Level::Trace => style.set_color(Color::Magenta),
};
let icon_style = env_logger::fmt::style::Style::new().fg_color(Some(
(match record.level() {
log::Level::Info => Color::Blue,
log::Level::Warn => Color::Yellow,
log::Level::Error => Color::Red,
log::Level::Debug => Color::Cyan,
log::Level::Trace => Color::Magenta,
})
.into(),
));

let icon = style.value(match record.level() {
let icon = match record.level() {
log::Level::Info => "ℹ",
log::Level::Warn => "⚠",
log::Level::Error => "✖",
log::Level::Debug => "⚙",
log::Level::Trace => "⚡",
});
};

let module = match record.level() {
log::Level::Debug => Some(style.value(record.module_path().unwrap())),
log::Level::Trace => Some(style.value(record.module_path().unwrap())),
log::Level::Debug => Some(record.module_path().unwrap()),
log::Level::Trace => Some(record.module_path().unwrap()),
_ => None,
};

let module_style = env_logger::fmt::style::Style::new().dimmed();

writeln!(
buf,
"{} {}{}",
"{icon_style}{}{icon_style:#} {module_style}{}{module_style:#}{}",
icon,
if let Some(module) = module {
format!("({}) ", module)
Expand Down

0 comments on commit 9a90df6

Please sign in to comment.