Skip to content

Commit

Permalink
new: Add colored log levels
Browse files Browse the repository at this point in the history
  • Loading branch information
camnwalter committed May 4, 2024
1 parent a8d1dd5 commit c60822b
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,18 @@ impl log::Log for KernelLogger {

fn log(&self, record: &Record<'_>) {
if self.enabled(record.metadata()) {
let color_code: &str = match record.level() {
log::Level::Error => "\x1b[31m", // red
log::Level::Debug => "\x1b[32m", // green
log::Level::Trace => "\x1b[35m", // magenta
log::Level::Warn => "\x1b[33m", // yellow
log::Level::Info => "\x1b[34m", // blue
};

let reset_color: &str = "\x1b[0m";

println!(
"[{}][{}] {}",
"{color_code}[{}][{}] {}{reset_color}",
crate::arch::core_local::core_id(),
record.level(),
record.args()
Expand Down

0 comments on commit c60822b

Please sign in to comment.