tklog是rust高性能结构化日志库,支持同步日志,异步日志,支持自定义日志的输出格式,支持按时间,按文件大小分割日志文件,支持日志文件压缩备份,支持官方日志库标准API,支持mod独立参数设置,支持日志level独立参数设置
LevelOption
对象,可以设置日志格式化输出#[test]
fn testlog() {
//将Info级别的日志格式设置为 Format::LevelFlag
//将Fatal级别的日志格式设置为 Format::LevelFlag | Format::Date
LOG.set_level_option(LEVEL::Info, LevelOption { format: Some(Format::LevelFlag), formatter: None })
.set_level_option(LEVEL::Fatal, LevelOption { format: Some(Format::LevelFlag | Format::Date), formatter: None});
trace!("this is trace log");
debug!("this is debug log");
info!("this is info log");
warn!("this is warn log");
error!("this is error log");
fatal!("this is fatal log");
thread::sleep(Duration::from_secs(1))
}
执行结果
---- testlog stdout ----
[DEBUG] 2024-08-24 15:06:02 test_0100.rs 17:this is debug log
[INFO] this is info log
[WARN] 2024-08-24 15:06:02 test_0100.rs 19:this is warn log
[ERROR] 2024-08-24 15:06:02 test_0100.rs 20:this is error log
[FATAL] 2024-08-24 this is fatal log
LogOption
对象,可以设置更多参数,包括设置日志文件#[test]
fn testlog() {
LOG.set_level_option(LEVEL::Info, LogOption { format: Some(Format::LevelFlag), formatter: None, level:None, console: None, fileoption: Some(Box::new(FileTimeMode::new("0200time.log", tklog::MODE::DAY, 0, false))) })
.set_level_option(LEVEL::Fatal, LogOption { format: Some(Format::LevelFlag | Format::Date), formatter: None, level: None, console: None, fileoption: Some(Box::new(FileSizeMode::new("0200size.log", 1<<10, 0, false)))});
trace!("this is trace log");
debug!("this is debug log");
info!("this is info log");
warn!("this is warn log");
error!("this is error log");
fatal!("this is fatal log");
thread::sleep(Duration::from_secs(1))
}
示例说明:
0200time.log
0200size.log