重写 Logger 以在输出中添加 __MODULE__

Joh*_*ith 2 elixir

Elixir 中是否可以覆盖 Logger 函数以始终在调用它的模块前面添加?"[#{__MODULE__}] "

喜欢

Logger.debug("Fetching Exchange Information and Trading Rules...")

变成日志:

[debug] [Elixir.Binance.Futures.Rest.Client] Requesting Exchange Information and Trading Rules...

Ale*_*kin 5

所请求的功能已经存在。只需按照文档Logger中的描述配置输出相应的元数据 ( ) 即可。:mfa

config :logger, :console,
  format: "[$level] [$metadata] $message\n",
  metadata: [:error_code, :mfa]
Run Code Online (Sandbox Code Playgroud)