Crate buffered_logger

Crate buffered_logger 

Source
Expand description

§buffered_logger

This is a file logger implemetation for crate log. It provides a buffer to save the log contents temporarily indeed of writing file every time. When the size of buffer exceeds the max buffer size, it writes the buffer to current log file. When the size of the current log file exceeds the max file size, the log file is rotated. It uses crate flate2 to compress rotatd file. It uses crate crossbeam-channel for multi-threading.

§Usage

use buffered_logger::Logger;

// Initialize the logger and start the service.
let logger = Logger::init(log::Level::Trace, "logs/m.log".to_string(), 10, 1024, 1024 * 5, true).unwrap();
logger.start();

// Now you can start logging.
log::info!("this is an info message");
log::debug!("this is a debug message");

// Logger is clonable. This is useful for passing it to a different thread.
let logger_clone = logger.clone();

// You can manually write the buffer to current log file. eg. run it every second.
logger_clone.flush();

// You can manually rotate the log file. eg. run it every day at 00:00.
logger_clone.rotate();

Structs§

Logger
The logger struct