tklog是rust高性能结构化日志库,支持同步日志,异步日志,支持自定义日志的输出格式,支持按时间,按文件大小分割日志文件,支持日志文件压缩备份,支持官方日志库标准API,支持mod独立参数设置,支持日志level独立参数设置
v0.2.9 更新内容
- 该版本主要实现支持 按时间与文件大小混合模式切割日志文件
两者方式可以设置
-
通过
**set_cutmode_by_mixed**设置 -
通过
**set_option**设置 -
测试程序地址: test_0_2_9.rs
一. 调用 .set_cutmode_by_mixed() 函数,参数:
-
文件路径
-
指定文件滚动大小
-
时间模式
-
最大备份日志文件数
-
是否压缩备份的日志文件
#[test] fn testlog() { LOG.set_cutmode_by_mixed("tklogs.log", 1 << 15,tklog::MODE::HOUR, 10, false);
trace!("trace!", "this is sync log"); debug!("debug!", "this is sync log"); info!("info!", "this is sync log"); warn!("warn!", "this is sync log"); error!("error!", "this is sync log"); fatal!("fata!", "this is sync log"); thread::sleep(Duration::from_secs(3))}
二. 调用 .set_option() 函数
#[test]
fn testlog2() {
let mut lo = tklog::LogOption::new();
lo.set_fileoption(tklog::handle::FileMixedMode::new("tklogs.log", 1 << 15,tklog::MODE::DAY, 10, false));
LOG.set_option(lo);
trace!("trace!", "this is sync log");
debug!("debug!", "this is sync log");
info!("info!", "this is sync log");
warn!("warn!", "this is sync log");
error!("error!", "this is sync log");
fatal!("fata!", "this is sync log");
thread::sleep(Duration::from_secs(3))
}
日志文件切分的结果:
-
按天与大小混合备份日期文件,如:
-
tklogs_20240521_1.log
-
tklogs_20240521_2.log
-
tklogs_20240521_3.log
-
tklogs_20240521_4.log
-
tklogs_20240522_1.log
-
tklogs_20240522_2.log
-
tklogs_20240522_3.log
-
tklogs_20240522_4.log
-
按小时与大小混合备份日志文件,如:
-
tklogs_2024052110_1.log
-
tklogs_2024052110_2.log
-
tklogs_2024052110_3.log
-
tklogs_2024052211_1.log
-
tklogs_2024052211_2.log
-
tklogs_2024052211_3.log
-
按月份与大小混合备份日志文件,如:
-
tklogs_202403_1.log
-
tklogs_202403_2.log
-
tklogs_202403_3.log
-
tklogs_202404_1.log
-
tklogs_202404_2.log
-
tklogs_202404_3.log