Log

Trait Log 

Source
pub trait Log: Sync + Send {
    // Required method
    fn log(&self, record: &Record<'_>);
}
Expand description

The logger backend trait.

Implement this trait and register it with inject_logger() to receive log records from the OSTD logging macros.

§Implementation guidelines

The logging macros can be called from any context: interrupt handlers, early boot, OOM handlers, or panic handlers. An implementation should be designed to work correctly in all of these contexts. In practice:

  • The ring buffer write must be heapless and lock-free (or IRQ-safe). The part of log() that records the message must not allocate from the heap and must use either a lock-free data structure or an IRQ-disabled spinlock, so that it is safe from any context.

  • Console flushing is best-effort. After recording the message, the implementation may attempt to flush pending messages to console devices synchronously. In contended or non-blockable contexts (e.g., scheduler code), the implementation should skip or defer flushing rather than blocking.

  • The implementation should be short. Long-running work can stall the calling CPU. Implementations should bound the work per log() call.

Required Methods§

Source

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

Logs a record.

The caller (the log! macro) has already verified that the record’s level passes both the compile-time and runtime level filters. The backend does not need to re-check the level.

Implementors§