How compositional loggers work in LoggingExtras
masterLoggingExtras uses a compositional model where complex logging systems are built by combining simple, pure components. These components are categorized into four types:
- Sinks: The endpoints of a log message (e.g., writing to a file or console). They only decide what to do with a message, not whether to accept it.
- Filters: Wrappers that decide whether to pass a message to the underlying logger. They can be Early Filters (deciding before the message is computed) or Active Filters (deciding after the message is fully formed).
- Transformers: Wrappers that modify log message content (like severity level or message text) before passing it on. They cannot block a message.
- Tee: A hub (specifically
TeeLogger) that receives one message and sends copies to multiple child loggers, allowing for complex routing.
By composing these, you can create sophisticated routing (e.g., sending errors to a file while sending everything to the console).
# Conceptual example of a composed logger
ConsoleLogger(stream, min_level) =
MinLevelLogger(
ActiveFilteredLogger(max_log_filter,
PureSinkConsoleLogger(stream)
),
min_level
)