Crates.io | rf_logger |
lib.rs | rf_logger |
version | 0.2.0 |
source | src |
created_at | 2023-11-10 00:54:47.809527 |
updated_at | 2023-11-10 00:54:47.809527 |
description | A logging implementation for `log` which can log to rotated files. |
homepage | |
repository | |
max_upload_size | |
id | 1030600 |
size | 10,561 |
Implements a logger that can log to stdout/stderr and rotated files
rf_logger
makes sense when used in executables (binary projects). Libraries should use the log
crate instead.
It must be added along with log
to the project dependencies:
[dependencies]
log = "0.4.0"
chrono = "0.4.31"
rf_logger = "0.2.0"
rf_logger
must be initialized as early as possible in the project. After it's initialized, you can use the log
macros to do actual logging.
Time formatting string can be set via Builder::time_fmt()
while other parts are fixed.
let _ = writeln!(
buf,
"{} - {} - {}",
now.format(&self.time_fmt),
record.level(),
record.args()
);
use log::{LevelFilter, info};
use rf_logger;
rf_logger::Builder::new()
.max_level(LevelFilter::Debug)
.stdout()
.rotated_file("tests/demo.log", 5 * 1024, 3)
.init();
There is a mutex lock during every log record beening handled, if performance is what your concern this crate may not be a good choice.