简体   繁体   English

如何将Elixir的总括应用程序名称添加到记录器元数据中?

[英]How can I put Elixir's umbrella app names into the logger metadata?

Umbrella apps are an interesting feature of Elixir, but I'm surprised the logging by default doesn't show which app is generating a log message. 伞应用程序是Elixir的一项有趣功能,但我很惊讶默认情况下的日志记录未显示哪个应用程序正在生成日志消息。 I'd like to add the umbrella app's name to the Logger metadata, but I'm not sure the best place to do that. 我想将伞形应用程序的名称添加到Logger元数据中,但是我不确定这样做的最佳位置。 Each app can configure the logger separately it seems and whitelist which metadata to show, but I'm not sure where to add the umbrella metadata 每个应用程序都可以分别配置看起来似乎的记录器,并将要显示的元数据列入白名单,但是我不确定在哪里添加伞形元数据

For example in apps/web/config/dev.exs I can put 例如在apps/web/config/dev.exs我可以放

config :logger, :console,
  metadata: [:umbrella_app]

But then I'm not finding a good place to add something like Logger.metadata(umbrella_app: :web) to populate the metadata. 但是后来我找不到添加Logger.metadata(umbrella_app: :web)来填充元数据的好地方。

Try adding :application to metadata 尝试将:application添加到元数据

config :logger, :console,
  format: "$metadata[$level] $message\n",
  metadata: [:application]

This will print message like this 这将打印这样的消息

application=app [level] Message application = app [级别]消息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM