更改跟踪订阅者的紧凑日志格式

huangapple go评论62阅读模式
英文:

Change tracing_subsciber's compact logger format

问题

tracing_subscriber 提供了一种紧凑的格式,看起来像这样:

DEBUG nh::nixos:51: out_dir: TempDir { path: "/tmp/nh-os-uC6E1T" }
DEBUG nh::nixos:52: out_link "/tmp/nh-os-uC6E1T/result"
 INFO nh::commands:131: Building NixOS configuration

我想要更改使用的符号( INFODEBUG 等),但我找不到如何做到这一点(如果这是否可能的话)。

/examples/examples/fmt-compact.rs

英文:

tracing_subscriber provides a compact format that looks like this:

DEBUG nh::nixos:51: out_dir: TempDir { path: "/tmp/nh-os-uC6E1T" }
DEBUG nh::nixos:52: out_link "/tmp/nh-os-uC6E1T/result"
 INFO nh::commands:131: Building NixOS configuration

I want to change the symbols used ( INFO, DEBUG, etc), but I can't find how (if this is possible at all).

/examples/examples/fmt-compact.rs

答案1

得分: 2

抱歉,这是不可能的。 Format 硬编码了级别名称

如果你真的想要这样做,你可以创建自己的类型来实现 FormatEvent,然后通过 Layer::event_format() 将其覆盖 Format

英文:

Unfortunately, this is not possible. Format hardcodes the level names.

If you really want to do that, you can make your own type implementing FormatEvent and overwrite Format with it via Layer::event_format().

huangapple
  • 本文由 发表于 2023年6月6日 01:28:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/76408743.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定