Need for Custom Logger

Logging in Rust

Rust implements logging using the facade pattern, a design concept from the "Gang of Four." Here's how it works:

This approach allows for flexibility—you can change the logging crate without altering your main code.

When logging in Rust, you typically import two libraries:

graph TD
    A["Source Code"] -->|"Uses"| B["log Crate (Facade)"]
    B -->|"Initializes"| C["Logging Implementation Crate"]
    C -->|"Implements"| D["Actual Logging Logic"]
    E["User's Application"] -->|"Calls"| B
    B -->|"Forwards Calls"| C

Custom Logger Implementation

Designing the Facade Log Crate

1. Level Enum

The Level enum represents the logger's verbosity levels, from lowest to highest priority:

#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash)]
pub enum Level {
    Trace,  // Extremely verbose, lowest priority
    Debug,  // Low-priority information
    Info,   // General information
    Warn,   // Potential issues
    Error,  // Serious problems
}

2. LevelFilter Enum