This commit is contained in:
2026-02-25 14:08:27 +01:00
parent 8a8034bd11
commit 4dc05c4151
23 changed files with 554 additions and 66 deletions

View File

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