Skip to main content

Loggable

Trait Loggable 

Source
pub trait Loggable {
    // Required method
    fn log(&self, msg: &str);

    // Provided methods
    fn info(&self, msg: &str) { ... }
    fn success(&self, msg: &str) { ... }
    fn warn(&self, msg: &str) { ... }
    fn error(&self, msg: &str) { ... }
    fn header(&self, _title: &str, _color_fn: fn(Colors) -> &'static str) { ... }
}
Expand description

Trait for logger output destinations.

This trait allows loggers to write to different destinations (console, files, test collectors) without hardcoding the specific destination. This makes loggers testable by allowing output capture.

This trait mirrors the Printable trait pattern used for printers, providing a unified interface for both production and test loggers.

Required Methods§

Source

fn log(&self, msg: &str)

Write a log message to the sink.

This is the core logging method that all loggers must implement. For Logger, this writes to the configured log file (if any). For TestLogger, this captures the message in memory for testing.

Provided Methods§

Source

fn info(&self, msg: &str)

Log an informational message.

Default implementation formats the message with INFO prefix and delegates to the log method.

Source

fn success(&self, msg: &str)

Log a success message.

Default implementation formats the message with [OK] prefix and delegates to the log method.

Source

fn warn(&self, msg: &str)

Log a warning message.

Default implementation formats the message with WARN prefix and delegates to the log method.

Source

fn error(&self, msg: &str)

Log an error message.

Default implementation formats the message with [ERROR] prefix and delegates to the log method.

Source

fn header(&self, _title: &str, _color_fn: fn(Colors) -> &'static str)

Print a section header with box drawing.

Default implementation does nothing (test loggers may not need headers). Production loggers override this to display styled headers.

Implementors§