Skip to content

Commit

Permalink
feat: bump version of env_logger and modify code for it
Browse files Browse the repository at this point in the history
Use default style of env_logger instead of custom style.
  • Loading branch information
Cyrix126 committed Feb 26, 2024
1 parent 7b60a88 commit 4db5163
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 54 deletions.
87 changes: 70 additions & 17 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ eframe = { version = "0.24.1", default-features = false, features = ["glow"] }
#egui_glow = { path = "external/egui/crates/egui_glow"}
#egui_extras = { path = "external/egui/crates/egui_extras", features = ["image"] }
#--------------------------------------------------------------------------------
env_logger = "0.10.2"
env_logger = "0.11.2"
figment = { version = "0.10.14", features = ["toml"] }
hyper = "0.14.28"
hyper-tls = "0.5.0"
Expand Down
48 changes: 12 additions & 36 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ use egui::{
};
use egui_extras::RetainedImage;
// Logging
use env_logger::{Builder, WriteStyle};
use env_logger::{
fmt::style::{AnsiColor, Style},
Builder, WriteStyle,
};
use log::*;
// Regex
use ::regex::Regex;
Expand Down Expand Up @@ -931,7 +934,6 @@ fn init_text_styles(ctx: &egui::Context, width: f32, pixels_per_point: f32) {
#[cold]
#[inline(never)]
fn init_logger(now: Instant) {
use env_logger::fmt::Color;
let filter_env = std::env::var("RUST_LOG").unwrap_or_else(|_| "INFO".to_string());
let filter = match filter_env.as_str() {
"error" | "Error" | "ERROR" => LevelFilter::Error,
Expand All @@ -944,42 +946,16 @@ fn init_logger(now: Instant) {

Builder::new()
.format(move |buf, record| {
let mut style = buf.style();
let level = match record.level() {
Level::Error => {
style.set_color(Color::Red);
"ERROR"
}
Level::Warn => {
style.set_color(Color::Yellow);
"WARN"
}
Level::Info => {
style.set_color(Color::White);
"INFO"
}
Level::Debug => {
style.set_color(Color::Blue);
"DEBUG"
}
Level::Trace => {
style.set_color(Color::Magenta);
"TRACE"
}
};
let level = record.level();
let level_style = buf.default_level_style(level);
let dimmed = Style::new().dimmed();
writeln!(
buf,
"[{}] [{}] [{}:{}] {}",
style.set_bold(true).value(level),
buf.style()
.set_dimmed(true)
.value(format!("{:.3}", now.elapsed().as_secs_f32())),
buf.style()
.set_dimmed(true)
.value(record.file().unwrap_or("???")),
buf.style()
.set_dimmed(true)
.value(record.line().unwrap_or(0)),
"{level_style}[{}]{level_style:#} [{dimmed}{}{dimmed:#}] [{dimmed}{}{dimmed:#}:{dimmed}{}{dimmed:#}] {}",
level,
format!("{:.3}", now.elapsed().as_secs_f32()),
record.file().unwrap_or("???"),
record.line().unwrap_or(0),
record.args(),
)
})
Expand Down

0 comments on commit 4db5163

Please sign in to comment.