From fcb123b02ff1e8460f5165e5531377a8c0bf3d3f Mon Sep 17 00:00:00 2001 From: griffi-gh Date: Thu, 19 Jan 2023 21:58:59 +0100 Subject: [PATCH] x --- src/logging.rs | 45 +++++++++++++++++++++++++++++++++++++++++++++ src/rendering.rs | 3 +++ 2 files changed, 48 insertions(+) create mode 100644 src/logging.rs create mode 100644 src/rendering.rs diff --git a/src/logging.rs b/src/logging.rs new file mode 100644 index 0000000..013b4e9 --- /dev/null +++ b/src/logging.rs @@ -0,0 +1,45 @@ +//! Custom env_logger options and styling + +use env_logger::{fmt::Color, Builder, Env}; +use log::Level; +use std::io::Write; + +pub fn init() { + let mut env = Env::default(); + if cfg!(debug_assertions) { + env = env.filter_or("RUST_LOG", "trace"); + } + Builder::from_env(env) + .format(|buf, record| { + let mut level_style = buf.style(); + level_style.set_color(match record.level() { + Level::Error => Color::Red, + Level::Warn => Color::Yellow, + _ => Color::Blue + }).set_bold(true); + + let mut location_style = buf.style(); + location_style.set_bold(true); + location_style.set_dimmed(true); + + let mut location_line_style = buf.style(); + location_line_style.set_dimmed(true); + + writeln!( + buf, + "{} {:<50}\t{}{}{}", + level_style.value(match record.level() { + Level::Error => "[e]", + Level::Warn => "[w]", + Level::Info => "[i]", + Level::Debug => "[d]", + Level::Trace => "[t]", + }), + format!("{}", record.args()), + location_style.value(record.target()), + location_line_style.value(" :"), + location_line_style.value(record.line().unwrap_or(0)) + ) + }) + .init(); +} diff --git a/src/rendering.rs b/src/rendering.rs new file mode 100644 index 0000000..db2ad61 --- /dev/null +++ b/src/rendering.rs @@ -0,0 +1,3 @@ +fn init_display() { + +}