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.