Expand description
A small logging library inspired by Python’s logging module.
The pieces fit together as a pipeline:
Loggeris the user-facing entry point (info,warning, …). It owns a level and a set of handlers, and builds aRecordper call.Handleris a sink (e.g.StreamHandler) that renders a record with itsFormatterand writes it somewhere.Formatterturns aRecordinto a string from a pattern like"%(timestamp) - %(level) - %(message)".Levelis the severity enum; records below a logger’s level are dropped.
Loggers are stored in a process-global registry, so Logger::get returns
a shared logger by name, and Logger::root is the parent of all loggers.
use logging::{Formatter, Logger, StreamHandler};
let logger = Logger::get("example");
logger
.add_handler(StreamHandler::with_pattern(std::io::stdout(), "%(level): %(message)"))
.unwrap();
logger.info("hello");Structs§
- Formatter
- Renders a
Recordinto a string according to a pattern. - Logger
- A named logger with a severity threshold and a set of
Handlers. - Parse
Level Error - The error returned when a string cannot be parsed into a
Level. - Stream
Handler - A
Handlerthat writes formatted records to anyWritesink, guarded by aMutexso a single stream can be shared across threads.
Enums§
- Level
- Severity level of a log message, ordered from least to most severe.
Traits§
- Handler
- A sink for log records. Implementors render the record (via their
Formatter) and deliver it somewhere (stdout, a file, …).
Type Aliases§
- Record
- A single log record: a map of field name to value, both borrowed for the
duration of the logging call (e.g.
"message","level","timestamp").