The log crate gives Rust code a single logging API that decouples libraries from any one logger backend. Executables pick and initialize a compatible implementation to emit output.
Overview
log is a Rust logging facade: libraries call shared macros and traits without binding to a specific output stack, and the final application chooses which logger actually records messages. If nothing is configured, the facade falls back to a noop path with very low overhead.
Each log event carries a target, level, and message body. Applications set a global logger once at startup; messages emitted before initialization are dropped. Standard macros cover error through trace levels, with filtering by configured maximum level.
Library authors are expected to depend only on log, while binaries wire in implementations such as env_logger, simplelog, log4rs, syslog adapters, platform log sinks, or WebAssembly-oriented loggers listed in the documentation. Optional features add structured key-value fields on records, boxed logger setup, compile-time max level stripping, and serde support for level types.
Custom backends implement the Log trait to control filtering and formatting. The crate documents patterns for executables, dynamic libraries, and compatibility notes between minor API generations.
Key features
- Macro-based leveled logging API
- Pluggable logger implementations
- Noop fallback when unset
- Optional structured kv feature
- Compile-time log level filters
- Log trait for custom backends
Use cases
- Library logging without backend lock-in
- Centralized app log configuration
- Structured diagnostic fields on records