diff --git a/Cargo.lock b/Cargo.lock index c423b49f..3a8d5b2a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -585,9 +585,9 @@ dependencies = [ "crossbeam-queue", "limine", "linked_list_allocator", + "log", "slab", "spin 0.9.4", - "tracing", "uart_16550", "versioning", "x86_64", diff --git a/kernel/Cargo.toml b/kernel/Cargo.toml index 33baa993..2a111c8d 100644 --- a/kernel/Cargo.toml +++ b/kernel/Cargo.toml @@ -8,7 +8,7 @@ linked_list_allocator = "0.9" slab = { version = "0.4", default-features = false } spin = "0.9" versioning = { git = "https://git.ablecorp.us/able/aos_userland" } -tracing = { version = "0.1", default-features = false, features = ["attributes"] } +log = "0.4" [dependencies.crossbeam-queue] version = "0.3" diff --git a/kernel/src/arch/x86_64/mod.rs b/kernel/src/arch/x86_64/mod.rs index 222af1d8..60b567fc 100644 --- a/kernel/src/arch/x86_64/mod.rs +++ b/kernel/src/arch/x86_64/mod.rs @@ -13,10 +13,9 @@ unsafe extern "C" fn _kernel_start() -> ! { static HDHM_REQ: LimineHhdmRequest = LimineHhdmRequest::new(0); static MMAP_REQ: LimineMmapRequest = LimineMmapRequest::new(0); - let _ = serial_fmt(format_args!( - "Initialising AbleOS Kernel {}\r\n", - crate::VERSION - )); + SERIAL_CONSOLE.lock().init(); + crate::logger::init().expect("failed to set logger"); + log::info!("Initialising AKern {}", crate::VERSION); memory::init_pt(VirtAddr::new( HDHM_REQ @@ -35,7 +34,6 @@ unsafe extern "C" fn _kernel_start() -> ! { ); allocator::init_alloc().expect("tried to initialise allocator"); - SERIAL_CONSOLE.lock().init(); crate::kmain::kmain() } diff --git a/kernel/src/debug.rs b/kernel/src/debug.rs deleted file mode 100644 index 981558fe..00000000 --- a/kernel/src/debug.rs +++ /dev/null @@ -1 +0,0 @@ -// TODO: Tracing Subscriber serial print implementation diff --git a/kernel/src/lib.rs b/kernel/src/lib.rs index a96c0cce..6b174318 100644 --- a/kernel/src/lib.rs +++ b/kernel/src/lib.rs @@ -7,7 +7,7 @@ extern crate alloc; pub mod allocator; pub mod arch; -pub mod debug; +pub mod logger; pub mod kmain; pub mod task; diff --git a/kernel/src/logger.rs b/kernel/src/logger.rs new file mode 100644 index 00000000..cc894eb9 --- /dev/null +++ b/kernel/src/logger.rs @@ -0,0 +1,33 @@ +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::serial_fmt(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) {} +}