forked from AbleOS/ableos
34 lines
877 B
Rust
34 lines
877 B
Rust
|
use log::{Level, SetLoggerError};
|
||
|
|
||
|
pub fn init() -> Result<(), SetLoggerError> {
|
||
|
log::set_logger(&crate::logger::Logger)?;
|
||
|
log::set_max_level(log::LevelFilter::Trace);
|
||
|
Ok(())
|
||
|
}
|
||
|
|
||
|
struct Logger;
|
||
|
impl log::Log for Logger {
|
||
|
fn enabled(&self, metadata: &log::Metadata) -> bool {
|
||
|
true
|
||
|
}
|
||
|
|
||
|
fn log(&self, record: &log::Record) {
|
||
|
let lvl = record.level();
|
||
|
crate::arch::log(format_args!(
|
||
|
"\x1b[38;5;{}m{lvl}\x1b[0m [{}]: {}\r\n",
|
||
|
match lvl {
|
||
|
Level::Error => "160",
|
||
|
Level::Warn => "172",
|
||
|
Level::Info => "47",
|
||
|
Level::Debug => "25",
|
||
|
Level::Trace => "103",
|
||
|
},
|
||
|
record.module_path().unwrap_or_default(),
|
||
|
record.args(),
|
||
|
))
|
||
|
.expect("write to serial console");
|
||
|
}
|
||
|
|
||
|
fn flush(&self) {}
|
||
|
}
|