Skip to content


Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Latest commit

* Add failing test for env var expansion

This test is has a `$ENV{var}` section as part of the pattern string,
right now the FixedWindowRoller does not expand that variable to its
corresponding env variable. This will make the test fail because the
expected rolled file path and actual rolled file path are different.

* Update expand_env_vars to use Into<Cow>

This change updates expand_env_vars to accept any type implementing
Into<Cow<'str,str> instead of just PathBufs. Functionally theres really
no change as the first thing the function did was convert the pathbuf
into a string which may or may not be mutated. Updating the type to be a
Cow (Clone On Write) smart pointer avoids any allocations for patterns
without environmental mixins.

This makes it easier to chain edits to the filename as the conditional
changes can be made on the Cow and converted to a Path when we open the

* Update rotate to take into account env vars

This commit updates the rotate function to expand any environmental
variable sections in the pattern argument.

Git stats


Failed to load latest commit information.
Latest commit message
Commit time
March 9, 2020 23:21
December 15, 2020 19:06
March 9, 2020 23:21
October 11, 2022 11:57
October 11, 2022 11:57
January 9, 2016 10:43
January 29, 2020 10:02


docs License: MIT OR Apache-2.0 CI Minimum rustc version

log4rs is a highly configurable logging framework modeled after Java's Logback and log4j libraries.


If you are using the file rotation in your configuration there is a known substantial performance issue so listen up! By default the gzip feature is enabled and when rolling files it will zip log archives automatically. This is a problem when the log archives are large as the zip happens in the main thread and will halt the process while the zip is completed. Be advised that the gzip feature will be removed from default features as of 1.0.

The methods to mitigate this are as follows.

  1. Use the background_rotation feature which spawns an os thread to do the compression.
  2. Disable the gzip feature with --no-default-features.
  3. Ensure the archives are small enough that the compression time is acceptable.

For more information see the PR that added background_rotation.

Quick Start


refresh_rate: 30 seconds
    kind: console
    kind: file
    path: "log/requests.log"
      pattern: "{d} - {m}{n}"
  level: warn
    - stdout
    level: info
    level: info
      - requests
    additive: false

use log::{error, info, warn};
use log4rs;

fn main() {
    log4rs::init_file("config/log4rs.yaml", Default::default()).unwrap();

    info!("booting up");

    // ...

Rust Version Requirements


Building for Dev

  • Run the tests: cargo test --all-features
  • Run the tests for windows with cross: cross test --target x86_64-pc-windows-gn
  • Run the tests for all individual features: ./
  • Run the tests for all individual features for windows with cross: ./ win


Licensed under either of

at your option.


Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you shall be dual licensed as above, without any additional terms or conditions.