#logger #log #logging

log4rs

A highly configurable multi-output logging implementation for the log facade

31 releases

✓ Uses Rust 2018 edition

0.10.0 Jan 29, 2020
0.9.0 Nov 29, 2019
0.8.3 Apr 3, 2019
0.8.1 Oct 17, 2018
0.3.1 Mar 26, 2015

#5 in Debugging

Download history 8256/week @ 2019-11-07 9816/week @ 2019-11-14 9278/week @ 2019-11-21 7940/week @ 2019-11-28 7999/week @ 2019-12-05 8334/week @ 2019-12-12 6066/week @ 2019-12-19 3915/week @ 2019-12-26 6805/week @ 2020-01-02 8226/week @ 2020-01-09 7817/week @ 2020-01-16 7406/week @ 2020-01-23 7463/week @ 2020-01-30 8094/week @ 2020-02-06 6879/week @ 2020-02-13

32,808 downloads per month
Used in 99 crates (57 directly)

MIT/Apache

185KB
4.5K SLoC

log4rs

docs crates.io 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.

Documentation

log4rs.yaml:

refresh_rate: 30 seconds
appenders:
  stdout:
    kind: console
  requests:
    kind: file
    path: "log/requests.log"
    encoder:
      pattern: "{d} - {m}{n}"
root:
  level: warn
  appenders:
    - stdout
loggers:
  app::backend::db:
    level: info
  app::requests:
    level: info
    appenders:
      - requests
    additive: false

lib.rs:

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

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

    info!("booting up");

    // ...
}

Rust Version Requirements

Since version 0.10.0 the minimum version for rust is 1.38.0 and is verified via CI. 1.38.0 is required for windows due to the backtrace crate. 1.34.0 may work for unix environments although it is not officially supported.

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: ./test.sh
  • Run the tests for all individual features for windows with cross: ./test.sh win

License

Licensed under either of

at your option.

Contribution

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.

Dependencies

~0.2–1MB
~19K SLoC