【问题标题】:Elixir logger backend: How does system call the init()?Elixir 记录器后端:系统如何调用 init()?
【发布时间】:2019-11-10 14:57:51
【问题描述】:

我正在编写一个自定义记录器后端。我研究了其他后端,例如:console、LoggerFileBackend、Timber.LoggerBackends.HTTP、Logger.Backends.Gelf。

其中一些,例如 :console 和 Timber.LoggerBackends.HTTP 使用 {__MODULE__, options} 初始化。其他一些像 LoggerFileBackend 和 Logger.Backends.Gelf 使用 {__MODULE__, name} 初始化。

问题:系统如何知道并正确调用后端的init(...)? 谢谢, 林。

【问题讨论】:

    标签: logging elixir backend


    【解决方案1】:

    我知道发生了什么。 我们在配置文件中配置backends的方式将决定参数如何传递给后端的init。

    例如:

    config :logger,
        backends: [:console ,{LoggerFileBackend, :app_log}, Timber.LoggerBackends.HTTP]
    

    然后系统会调用init如下:

    # for console, it will call:
    init(:console)
    
    # for LoggerFileBackend, it will call with name set to ":app_log"
    init({__MODULE__, name})
    
    # for Timber.LoggerBackends.HTTP, it will call with options omitted
    init(__MODULE__, options \\ [])
    

    【讨论】:

      猜你喜欢
      • 2019-11-03
      • 2013-03-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-15
      • 2021-10-26
      • 2011-06-29
      • 2015-01-17
      相关资源
      最近更新 更多