What is log4rs?

log4rs (2015) is a logging implementation for the log facade — inspired by Java’s Log4j. It supports multiple appenders (console, rolling files), encoders, and filter levels, often driven by a YAML or TOML config file so ops can change logging without recompiling.

It is not a structured tracing framework: no spans, limited key-value structure. Use it when you already emit log::info! and need production-grade file rotation and external configuration.

Simple example (code init)

use log::info;

fn main() -> Result<(), Box> {
    log4rs::init_file("log4rs.yaml", Default::default())?;

    info!("application started");
    Ok(())
}

Example log4rs.yaml

appenders:
  stdout:
    kind: console
  file:
    kind: rolling_file
    path: "logs/app.log"
    policy:
      trigger:
        kind: size
        limit: 10mb
      roller:
        kind: fixed_window
        pattern: "logs/app.{}.log"
        count: 5

root:
  level: info
  appenders:
    - stdout
    - file

Libraries still use log macros; log4rs only decides where those lines go and at what level.

For structured fields and async request tracing, see tracing.