您现在的位置是:首页 > 文章详情

Rust 日志库 tklog 0.2.9 — 支持混合时间文件大小备份模式

日期:2024-12-30点击:79
tklog是rust高性能结构化日志库,支持同步日志,异步日志,支持自定义日志的输出格式,支持按时间,按文件大小分割日志文件,支持日志文件压缩备份,支持官方日志库标准API,支持mod独立参数设置,支持日志level独立参数设置
  1. 简介
  2. Github地址
  3. 仓库地址
  4. rust日志库性能压测 — log4rs + tracing + tklog
  5. 记录tklog压测结果

v0.2.9 更新内容

  • 该版本主要实现支持 按时间与文件大小混合模式切割日志文件

两者方式可以设置

  • 通过 set_cutmode_by_mixed  设置
  • 通过 set_option  设置
  • 测试程序地址:  test_0_2_9.rs

 

一. 调用 .set_cutmode_by_mixed() 函数,参数:

  1. 文件路径  
  2. 指定文件滚动大小
  3. 时间模式
  4. 最大备份日志文件数
  5. 是否压缩备份的日志文件
 #[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
原文链接:https://www.oschina.net/news/327159/tklog-0-2-9-released
关注公众号

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。

持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。

转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。

文章评论

共有0条评论来说两句吧...

文章二维码

扫描即可查看该文章

点击排行

推荐阅读

最新文章