Releases: donnie4w/tklog
Releases · donnie4w/tklog
v0.2.6
v0.2.5
v0.2.4
v0.2.3
v0.2.2
v0.2.1
v0.2.0
增加支持日志级别设置独立日志格式参数,设置日志文件
tklog 通过 set_level_option()
设置日志级别的独立日志参数
set_level_option()
接收 任意实现 OptionTrait
特征的对象
示例1 :参数 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
示例2 参数 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))
}
示例说明:
- Info级别的文件日志设置为按天分隔,文件名
0200time.log
- Fatal级别的文件日志设置为按大小分隔,文件名
0200size.log
v0.1.0
Add:
tklog Supports Independent Logging Format Parameters for Log Levels
tklog Independent Logging Format Parameters for Log Levels via set_level_option()
#[test]
fn testlog() {
// Set the log format for Info level to include Format::LevelFlag.
// Set the log format for Fatal level to include Format::LevelFlag and 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))
}
Execution Result
---- 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
v0.0.10
release 0.0.10
增加支持自定义日志多参数分隔符函数 set_separator
tklog
allows setting custom separators using the set_separator()
method
the following Rust code demonstrates how to configure and use custom separators for log entries in the tklog
framework:
#[test]
fn testlog() {
log_init();
trace!("trace>>>>", "aaaaaaaaa", 1, 2, 3, 4);
debug!("debug>>>>", "bbbbbbbbb", 1, 2, 3, 5);
LOG.set_separator("|"); //设置参数分隔符 |
info!("info>>>>", "ccccccccc", 1, 2, 3, 5);
warn!("warn>>>>", "dddddddddd", 1, 2, 3, 6);
LOG.set_separator(","); //设置参数分隔符 ,
error!("error>>>>", "eeeeeeee", 1, 2, 3, 7);
fatal!("fatal>>>>", "ffffffff", 1, 2, 3, 8);
thread::sleep(Duration::from_secs(1))
}
Execution Result
The output generated by the testlog function demonstrates the impact of setting different separators on the log messages:
---- testlog stdout ----
[TRACE] 2024-08-15 14:14:19.289590 tests\testsynclog.rs 22:trace>>>>aaaaaaaaa1234
[DEBUG] 2024-08-15 14:14:19.289744 tests\testsynclog.rs 23:debug>>>>bbbbbbbbb1235
[INFO] 2024-08-15 14:14:19.289761 tests\testsynclog.rs 25:info>>>>|ccccccccc|1|2|3|5
[WARN] 2024-08-15 14:14:19.289774 tests\testsynclog.rs 26:warn>>>>|dddddddddd|1|2|3|6
[ERROR] 2024-08-15 14:14:19.289789 tests\testsynclog.rs 28:error>>>>,eeeeeeee,1,2,3,7
[FATAL] 2024-08-15 14:14:19.289802 tests\testsynclog.rs 29:fatal>>>>,ffffffff,1,2,3,8