#logging #log #logger

rf_logger

A logging implementation for log which can log to rotated files

1 unstable release

0.2.0 Nov 10, 2023

#666 in Debugging

MIT license

11KB
206 lines

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.

Dependencies

~1.5MB
~19K SLoC