1
0
Fork 0
forked from AbleOS/ableos
ableos_time/ableos/src/logger.rs

53 lines
1.5 KiB
Rust
Raw Normal View History

2022-01-16 19:42:11 -06:00
use crate::serial_println;
use lliw::{Fg, Reset};
pub use log::{debug, info, trace, warn};
use log::{Level, Metadata, Record};
struct SimpleLogger;
impl log::Log for SimpleLogger {
fn enabled(&self, metadata: &Metadata) -> bool {
metadata.level() <= Level::Trace
}
fn log(&self, record: &Record) {
if self.enabled(record.metadata()) {
let color; // = (Fg::Reset, "$GREEN$");
match record.level() {
log::Level::Error => color = (Fg::Red, "$RED$"),
log::Level::Warn => color = (Fg::LightYellow, "$LIGHTYELLOW$"),
log::Level::Info => color = (Fg::LightWhite, "$LIGHTGRAY$"),
log::Level::Debug => color = (Fg::Blue, "$BLUE$"),
log::Level::Trace => color = (Fg::Yellow, "$YELLOW$"),
}
println!(
"[{}{}$RESET$][$GREEN$FakeTempTime$RESET$] {}",
color.1,
record.level(),
record.args()
);
serial_println!(
"[{}{}{}][{}FakeTempTime{}] {}",
color.0,
record.level(),
Fg::Reset,
Fg::Green,
Reset,
record.args()
);
}
}
fn flush(&self) {}
}
use log::{LevelFilter, SetLoggerError};
static LOGGER: SimpleLogger = SimpleLogger;
pub fn init() -> Result<(), SetLoggerError> {
log::set_logger(&LOGGER).map(|()| log::set_max_level(LevelFilter::Trace))
}