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)) }