mirror of
https://github.com/panpaul/tiny_os
synced 2024-09-20 09:45:19 +08:00
chore: support colorful log
This commit is contained in:
parent
f86b061470
commit
9628d32d54
@ -6,7 +6,7 @@ edition = "2021"
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[features]
|
||||
default = ["arch_riscv64", "board_virt"]
|
||||
default = ["arch_riscv64", "board_virt", "log_color"]
|
||||
arch_riscv64 = []
|
||||
arch_riscv32 = []
|
||||
arch_arm = []
|
||||
@ -14,6 +14,7 @@ arch_x86 = []
|
||||
board_default = []
|
||||
board_virt = []
|
||||
board_thead = []
|
||||
log_color = []
|
||||
|
||||
[profile.dev]
|
||||
panic = "abort"
|
||||
|
@ -14,8 +14,27 @@ impl Log for SimpleLogger {
|
||||
return;
|
||||
}
|
||||
|
||||
let (color_prefix, color_reset) = if cfg!(feature = "log_color") {
|
||||
let color = match record.level() {
|
||||
log::Level::Error => "\x1b[31m",
|
||||
log::Level::Warn => "\x1b[33m",
|
||||
log::Level::Info => "\x1b[32m",
|
||||
log::Level::Debug => "\x1b[34m",
|
||||
log::Level::Trace => "\x1b[37m",
|
||||
};
|
||||
(color, "\x1b[0m")
|
||||
} else {
|
||||
("", "")
|
||||
};
|
||||
|
||||
RawConsole
|
||||
.write_fmt(format_args!("[{}] {}\n", record.level(), record.args()))
|
||||
.write_fmt(format_args!(
|
||||
"{}[{}] {}{}\n",
|
||||
color_prefix,
|
||||
record.level(),
|
||||
record.args(),
|
||||
color_reset
|
||||
))
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user