A standalone, #![no_std]
-friendly Logger
crate.
Based on the design of the logger built into the bootloader crate and meant to be used in OS kernels.
To use this crate, specify it as a dependency in your kernel's Cargo.toml
, then initialize it.
The logger needs to be initialized in order to be used. To do that, one must first create a global instance, using a crate like conquer_once
:
pub static PRINTK: OnceCell<LockedPrintk> = OnceCell::uninit();
After this, the log
crate needs to be attached to it. This requires the following 2 steps:
get_or_init
method to unwrap the LockedPrintk
object from its outer OnceCelllog::set_logger
to tell the log
crate what to attach tolog::set_max_level to tell the
log` crate how many levels of logging you want to doHere's an example function demonstrating how this is done in pure Rust:
pub fn printk_init(buffer: &'static mut [u8], info: FrameBufferInfo) {
let kernel_logger = printk::PRINTK.get_or_init(move || printk::LockedPrintk::new(buffer, info));
log::set_logger(kernel_logger).expect("logger already set");
log::set_max_level(log::LevelFilter::Trace);
log::info!("Hello, Kernel!");
}
If you have any functionality to add, feel free to create a pull request. I'll gladly test and accept it. Also, if you have any bugs to report, that is also what GitHub is for.