rf_logger

Crates.iorf_logger
lib.rsrf_logger
version0.2.0
sourcesrc
created_at2023-11-10 00:54:47.809527
updated_at2023-11-10 00:54:47.809527
descriptionA logging implementation for `log` which can log to rotated files.
homepage
repository
max_upload_size
id1030600
size10,561
(TedQue)

documentation

https://docs.rs/rf_logger

README

rf_logger

Implements a logger that can log to stdout/stderr and rotated files

Usage

In libraries

rf_logger makes sense when used in executables (binary projects). Libraries should use the log crate instead.

In executables

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.

Formatting

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()
);

Examples

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();

Notes

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.

Commit count: 0

cargo fmt