Crates.io | tracing-plus |
lib.rs | tracing-plus |
version | 0.1.8 |
created_at | 2025-07-08 09:30:54.660603+00 |
updated_at | 2025-08-27 06:22:20.461479+00 |
description | 对tracing日志库的增强,通过日志配置文件,注册日志 |
homepage | |
repository | https://gitee.com/itao007/tracing-plus.git |
max_upload_size | |
id | 1742355 |
size | 75,237 |
该库是对tracing库的增强
在项目的的根目录创建一个文件名为tracing-log.toml
或tracing-log.yaml
或tracing-log.yml
的文件,
该库会根据配置文件动态的注册日志,然后调用init_tracing_log
方法即可完成日志的初始化工作
优先级 toml > yaml > yml
# 文件名 tracing-log.toml
# 控制台输出配置
[console]
# 日志级别, 必填(可选值:`error`、`warn`、`info`、`debug`、`trace`)
level = "info"
# 是否打印线程名 默认为 true
thread = true
# 时间格式 默认为 "%Y-%m-%d %H:%M:%S"
format = "%Y-%m-%d %H:%M:%S"
# 是否打印行号 默认为 false
line-number = true
# 文件输出配置
[[file]]
# 日志级别, 必填(可选值:`error`、`warn`、`info`、`debug`、`trace`)
level = "info"
# 是否打印线程名 默认为 true
thread = true
# 时间格式 默认为 "%Y-%m-%d %H:%M:%S"
format = "%Y-%m-%d %H:%M:%S"
# 是否打印行号 默认为 false
line-number = true
# 保留的最大文件数量 默认为 30
max-files = 60
# 日志文件滚动的固定时间段,可选值: "minutely"、"hourly"、"daily"、"never", 默认值为: "daily"
rotation = "daily"
# 生成的文件名前缀, 必填
prefix = "info"
# 生成的文件名后缀, 默认值为: "log"
suffix = "log"
# 生成的文件所在目录前缀, 默认值为: "logs"
directory = "logs"
# 只记录`target`指定的值的日志 (不配置,则记录全部)
target = "abc"
[[file]]
level = "error"
thread = false
format = "%Y-%m-%d %H:%M:%S"
line-number = true
max-files = 60
rotation = "daily"
prefix = "error"
directory = "logs"
[[file]]
level = "worker"
thread = false
format = "%Y-%m-%d %H:%M:%S"
line-number = true
max-files = 60
rotation = "daily"
prefix = "error"
directory = "logs"
target = "worker"