tklog 0.2.3 — Rust 高性能日志库,日志标识格式自定义设置
tklog是rust高性能结构化日志库,支持同步日志,异步日志,支持自定义日志的输出格式,支持按时间,按文件大小分割日志文件,支持日志文件压缩备份,支持官方日志库标准API,支持mod独立参数设置,支持日志level独立参数设置
v0.2.3 版本更新
新增支持对日志属性标识进行格式化设置,如: [DEBUG] [INFO][WARN][ERROR][FATAL]标识,时间格式化标识
通过 set_attr_format
函数设置日志标识与时间格式
示例1:同步日志打印
fn testlog() {
tklog::LOG.set_attr_format(|fmt| {
fmt.set_level_fmt(|level| {
match level {
LEVEL::Trace => "[T]",
LEVEL::Debug => "[D]",
LEVEL::Info => "[I]",
LEVEL::Warn => "[W]",
LEVEL::Error => "[E]",
LEVEL::Fatal => "[F]",
LEVEL::Off => "",
}.to_string()
});
fmt.set_time_fmt(|| {
let now: DateTime<Local> = Local::now();
(now.format("%Y/%m/%d").to_string(), now.format("%H:%M:%S").to_string(), "".to_string())
});
});
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(1))
}
执行结果:
[D] 2024/10/17 19:41:20 test_0230.rs 32:debug!this is sync log
[I] 2024/10/17 19:41:20 test_0230.rs 33:info!this is sync log
[W] 2024/10/17 19:41:20 test_0230.rs 34:warn!this is sync log
[E] 2024/10/17 19:41:20 test_0230.rs 35:error!this is sync log
[F] 2024/10/17 19:41:20 test_0230.rs 36:fata!this is sync log
示例2:异步日志打印
#[tokio::test]
async fn asynctestlog() {
ASYNC_LOG.set_attr_format(|fmt| {
fmt.set_level_fmt(|level| {
match level {
LEVEL::Trace => "[AT]",
LEVEL::Debug => "[AD]",
LEVEL::Info => "[AI]",
LEVEL::Warn => "[AW]",
LEVEL::Error => "[AE]",
LEVEL::Fatal => "[AF]",
LEVEL::Off => "",
}
.to_string()
});
});
async_trace!("trace!", "this is async log");
async_debug!("debug!", "this is async log");
async_info!("info!", "this is async log");
async_warn!("warn!", "this is async log");
async_error!("error!", "this is async log");
async_fatal!("fata!", "this is async log");
tokio::time::sleep(tokio::time::Duration::from_secs(3)).await;
}

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
-
上一篇
Unity 6 正式发布:大幅提升稳定性和性能、渲染速度更快
Unity 6 已正式发布,与上一个主要版本相比,Unity 6 大幅提升了稳定性和性能,并且为所有 Unity 客户提供更强大的支持。 这是一个 LTS 版本,官方承诺在下一个主要版本发布后至少再提供两年的支持服务。 Unity 6 还引入了全新的版本更新方法,这种方法能够不断提高引擎的性能和稳定性,同时确保升级更轻松、更少中断。总的来说,Unity 6 将维持三种版本类型: 1) 主要版本(如 Unity 6); 2) 补丁版本,提供错误修复和工作流程改进,但不提供新功能; 3) 一种称为“更新”的新版本类型,将遵循 6.X 命名法。 更新中将提供可选和附加的新功能,但不会破坏与当前引擎版本的兼容性。目前 Unity 团队已经在开发第一个 Unity 6 更新,即 Unity 6.1,并将于 2025 年 4 月发布。 Unity 6 有许多令人兴奋的新工具和功能,让开发者体验更快的渲染速度、更强大的光照控制、端到端的多人游戏工作流程、智能化的动态 AI 功能,以及对移动 Web Runtime 的更多支持。 端到端多人游戏工作流程将加速联网游戏的开发; 各种工具可以助力开发者开发...
-
下一篇
Elasticsearch 8.15.3 发布
Elasticsearch 是一个基于 Lucene 库的搜索引擎。它提供了一个分布式、支持多租户的全文搜索引擎,具有 HTTP Web 接口和无模式 JSON 文档。Elasticsearch 基于 Java 开发,并在 SSPL + Elastic License 双重授权许可下作为开源软件发布。 Elasticsearch 8.15.3 现已发布,具体更新内容如下: Bug 修复 Aggregations 如果 internal stats 为空,则不验证#113846(issue:#113811) 修复GlobalOrdCardinalityAggregator中的needsScore计算#113129(issue:#112975) Authorization 启用 cluster state role mapper,在角色解析中包含 ECK operator-defined role mappings#114337 ES|QL ES|QL:确保PlanStreamInput缓存的最小容量#114116 ES|QL:从InferIsNotNull规则检查中跳过 CASE 函数#...
相关文章
文章评论
共有0条评论来说两句吧...
文章二维码
点击排行
推荐阅读
最新文章
- Windows10,CentOS7,CentOS8安装Nodejs环境
- SpringBoot2全家桶,快速入门学习开发网站教程
- Docker快速安装Oracle11G,搭建oracle11g学习环境
- CentOS8编译安装MySQL8.0.19
- Springboot2将连接池hikari替换为druid,体验最强大的数据库连接池
- Dcoker安装(在线仓库),最新的服务器搭配容器使用
- CentOS7,CentOS8安装Elasticsearch6.8.6
- Docker使用Oracle官方镜像安装(12C,18C,19C)
- SpringBoot2整合MyBatis,连接MySql数据库做增删改查操作
- SpringBoot2配置默认Tomcat设置,开启更多高级功能