Crates.io | log4rs |
lib.rs | log4rs |
version | 1.4.0 |
created_at | 2015-01-28 17:02:11.902393+00 |
updated_at | 2025-09-05 16:44:10.622502+00 |
description | A highly configurable multi-output logging implementation for the `log` facade |
homepage | |
repository | https://github.com/estk/log4rs |
max_upload_size | |
id | 1309 |
size | 348,344 |
log4rs is a highly configurable logging framework modeled after Java's Logback and log4j libraries.
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");
// ...
}
1.75
Run the tests: cargo test --all-features
Run the tests for windows with cross:
cross test --target x86_64-pc-windows-gnu
Run the tests for all individual features: ./test.sh
Run the tests for all individual features for windows with
cross: ./test.sh win
If you are using the file rotation in your configuration there is a known
substantial performance issue with either the gzip
or zstd
features. When rolling files it will zip log archives automatically. This is
a problem when the log archives are large as the zip process occurs in
the main thread and will halt the process until the zip process
completes.
The methods to mitigate this are as follows.
background_rotation
feature which spawns an os thread to do the compression.gzip
nor the zstd
features.For more information see the PR that added background_rotation
.
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.