log4rs日志库使用toml格式文件配置:
Cargo.toml:(默认为"yaml_format")
[dependencies]
log4rs = {version="*",features = ["toml_format"]}
log4rs.yaml
# Scan this file for changes every 30 seconds
refresh_rate: 30 seconds
appenders:
# An appender named "stdout" that writes to stdout
stdout:
kind: console
encoder:
pattern: "{d(%+)(local)} [{t}] {h({l})} {M}:{m}{n}"
# An appender named "requests" that writes to a file with a custom pattern encoder
requests:
kind: file
path: "log/requests.log"
encoder:
pattern: "{d(%+)(local)} [{t}] {h({l})} {M}:{m}{n}"
# Set the default logging level to "info" and attach the "stdout"、"requests appender to the root
root:
level: info
appenders:
- stdout
- requests
loggers:
# Raise the maximum log level for events sent to the "app::backend::db" logger to "info"
app::backend::db:
level: info
# Route log events sent to the "app::requests" logger to the "requests" appender,
# and *not* the normal appenders installed at the root
app::requests:
level: info
appenders:
- requests
additive: false
转换后的log4rs.toml
# Scan this file for changes every 30 seconds
refresh_rate="30 seconds"
[appenders]
# An appender named "stdout" that writes to stdout
stdout={kind="console", encoder={pattern="{d(%+)(local)} [{t}] {h({l})} {M}:{m}{n}"}}
# An appender named "requests" that writes to a file with a custom pattern encoder
requests={kind="file", path="log/requests.log", encoder={pattern="{d(%+)(local)} [{t}] {h({l})} {M}:{m}{n}"}}
# Set the default logging level to "info" and attach the "stdout"、"requests appender to the root
[root]
level="info"
appenders=["stdout","requests"]
[loggers]
# Raise the maximum log level for events sent to the "app::backend::db" logger to "info"
"app::backend:db"={level="info"}
# Route log events sent to the "app::requests" logger to the "requests" appender,
# and *not* the normal appenders installed at the root
"app::requests"={level="info",appenders=["requests"],additive=false}