Crates.io | pipe-logger-lib |
lib.rs | pipe-logger-lib |
version | 1.1.17 |
source | src |
created_at | 2018-09-12 16:11:06.221225 |
updated_at | 2023-09-09 12:17:45.589927 |
description | Stores, rotates, compresses process logs. |
homepage | https://magiclen.org/pipe-logger-lib |
repository | https://github.com/magiclen/pipe-logger-lib |
max_upload_size | |
id | 84383 |
size | 30,243 |
Stores, rotates, compresses process logs.
use pipe_logger_lib::*;
use std::fs;
use std::path::Path;
let test_folder = {
let folder = Path::join(&Path::join(Path::new("tests"), Path::new("out")), "log-example");
fs::remove_dir_all(&folder);
fs::create_dir_all(&folder).unwrap();
folder
};
let test_log_file = Path::join(&test_folder, Path::new("mylog.txt"));
let mut builder = PipeLoggerBuilder::new(&test_log_file);
builder
.set_tee(Some(Tee::Stdout))
.set_rotate(Some(RotateMethod::FileSize(30))) // bytes
.set_count(Some(10))
.set_compress(false);
{
let mut logger = builder.build().unwrap();
logger.write_line("Hello world!").unwrap();
let rotated_log_file_1 = logger.write_line("This is a convenient logger.").unwrap().unwrap();
logger.write_line("Other logs...").unwrap();
logger.write_line("Other logs...").unwrap();
let rotated_log_file_2 = logger.write_line("Rotate again!").unwrap().unwrap();
logger.write_line("Ops!").unwrap();
}
fs::remove_dir_all(test_folder).unwrap();
Now, the contents of test_log_file
are,
Ops!
The contents of rotated_log_file_1
are,
Hello world!
This is a convenient logger.
The contents of rotated_log_file_2
are,
Other logs...
Other logs...
Rotate again!
https://crates.io/crates/pipe-logger-lib
https://docs.rs/pipe-logger-lib
https://crates.io/crates/pipe-logger