Refactor
This commit is contained in:
16
src/io.rs
16
src/io.rs
@@ -1,16 +1,25 @@
|
||||
//! Kernel I/O helpers and logging frontend.
|
||||
//!
|
||||
//! Provides a lightweight logger implementation routing to UART and helper
|
||||
//! macros for printing from kernel code.
|
||||
use crate::println;
|
||||
|
||||
use alloc::format;
|
||||
use alloc::string::String;
|
||||
|
||||
use log::{Level, Metadata, Record};
|
||||
use log::{LevelFilter, SetLoggerError};
|
||||
|
||||
use crate::uart::write_uart;
|
||||
|
||||
pub(crate) fn print(content: String) {
|
||||
/// Print a string to the kernel console (via UART).
|
||||
///
|
||||
/// Accepts any type that implements `AsRef<str>` to avoid unnecessary
|
||||
/// allocations at call sites.
|
||||
pub(crate) fn print<T: AsRef<str>>(content: T) {
|
||||
write_uart(content);
|
||||
}
|
||||
|
||||
/// Logger implementation that routes kernel log records to the UART-based console.
|
||||
struct Logger;
|
||||
|
||||
impl log::Log for Logger {
|
||||
@@ -39,6 +48,9 @@ impl log::Log for Logger {
|
||||
|
||||
static LOGGER: Logger = Logger;
|
||||
|
||||
/// Initialize the kernel logger and set the default level.
|
||||
///
|
||||
/// Returns an error if a global logger has already been set.
|
||||
pub fn init_log() -> Result<(), SetLoggerError> {
|
||||
log::set_logger(&LOGGER).map(|()| log::set_max_level(LevelFilter::Info))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user