2022-01-25 19:40:37 -06:00
|
|
|
use core::sync::atomic::Ordering;
|
|
|
|
|
2022-01-16 19:42:11 -06:00
|
|
|
use crate::serial_println;
|
2022-02-28 08:54:41 -06:00
|
|
|
use kernel::TICK;
|
2022-01-16 19:42:11 -06:00
|
|
|
use lliw::{Fg, Reset};
|
|
|
|
pub use log::{debug, info, trace, warn};
|
|
|
|
use log::{Level, Metadata, Record};
|
|
|
|
|
2022-01-25 19:40:37 -06:00
|
|
|
use crate::arch::drivers::timer::TIMER_INTERRUPT_HERTZ;
|
|
|
|
|
2022-01-16 19:42:11 -06:00
|
|
|
struct SimpleLogger;
|
2022-02-07 07:33:40 -06:00
|
|
|
// TODO: Rebuild this to take advantage of sockets
|
|
|
|
// DETAIL: Log to a socket instead of the screen
|
|
|
|
// So that we can log in the kernel and display it in userland
|
2022-01-16 19:42:11 -06:00
|
|
|
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()) {
|
2022-01-25 19:40:37 -06:00
|
|
|
let color;
|
|
|
|
let time = TICK.load(Ordering::Relaxed) as f64;
|
|
|
|
|
2022-02-19 07:17:44 -06:00
|
|
|
let time_float = time;
|
2022-01-16 19:42:11 -06:00
|
|
|
|
|
|
|
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$"),
|
|
|
|
}
|
2022-01-25 19:40:37 -06:00
|
|
|
|
2022-01-16 19:42:11 -06:00
|
|
|
serial_println!(
|
2022-01-25 19:40:37 -06:00
|
|
|
"[{}{}{}][{}{}{}] {}",
|
2022-01-16 19:42:11 -06:00
|
|
|
color.0,
|
|
|
|
record.level(),
|
|
|
|
Fg::Reset,
|
|
|
|
Fg::Green,
|
2022-01-25 19:40:37 -06:00
|
|
|
time_float,
|
2022-01-16 19:42:11 -06:00
|
|
|
Reset,
|
2022-01-25 19:40:37 -06:00
|
|
|
record.args(),
|
2022-01-16 19:42:11 -06:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2022-01-26 19:43:03 -06:00
|
|
|
/// Clear the log buffer
|
2022-01-16 19:42:11 -06:00
|
|
|
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))
|
|
|
|
}
|