Skip to main content

Logger

Trait Logger 

Source
pub trait Logger: Send + Sync {
    // Required methods
    fn log(&self, record: &Record<'_>);
    fn flush(&self);
    fn enabled(&self, level: Level) -> bool;
}
Expand description

Logger trait - the kernel mechanism for logging.

Drivers implement this trait to provide actual log output. The kernel only defines the interface, not the policy (where logs go, formatting, etc.).

§Thread Safety

Implementations must be Send + Sync as the logger is accessed from multiple threads concurrently. Implementations should be lock-free or use minimal locking to avoid blocking the caller.

§Example

use reovim_kernel::api::v1::*;

struct StderrLogger;

impl Logger for StderrLogger {
    fn log(&self, record: &Record) {
        eprintln!("[{}] {}: {}",
            record.level(),
            record.file(),
            record.message());
    }

    fn flush(&self) {
        // stderr is unbuffered by default
    }

    fn enabled(&self, level: Level) -> bool {
        level <= Level::Debug  // Log everything except Trace
    }
}

Required Methods§

Source

fn log(&self, record: &Record<'_>)

Log a record.

This method should be fast and non-blocking. If the logger buffers output, it should do so efficiently.

Source

fn flush(&self)

Flush any buffered output.

Called to ensure all pending logs are written. May be called before program exit or when immediate output is needed.

Source

fn enabled(&self, level: Level) -> bool

Check if a level is enabled for logging.

This method is called before formatting the log message, allowing early exit if the level is not enabled. This avoids the cost of string formatting when logging is disabled.

Implementors§