What is the log crate?
log (2014) is the standard logging facade for Rust —
not a full logger. It defines macros (info!,
warn!, error!, …) and the
Log trait. A separate crate must be installed as the
logger implementation at runtime.
Libraries use log so applications can choose any backend
without forcing a dependency on tracing or
slog.
Simple example
use log::{info, warn};
fn main() {
env_logger::init(); // backend: reads RUST_LOG env var
info!("server starting");
warn!("cache miss for key={}", "user:42");
}
Run with filter:
RUST_LOG=info cargo run
Common backends
| Backend | Use case |
|---|---|
env_logger |
CLI tools, development — minimal setup |
log4rs |
Production file appenders, YAML/TOML config |
tracing-log |
Forward log records into tracing |
See also: tracing for structured logging and spans in async services.