[英]Elixir logger backend: How does system call the init()?
我正在編寫自定義記錄器后端。 我研究其他后端,例如:控制台,LoggerFileBackend,Timber.LoggerBackends.HTTP,Logger.Backends.Gelf。
其中一些,例如:console和Timber.LoggerBackends.HTTP已使用{__MODULE__, options}
進行初始化。 諸如LoggerFileBackend和Logger.Backends.Gelf之類的其他一些具有{__MODULE__, name}
init。
問題:系統如何正確知道並為后端正確調用init(...)
? 謝謝你,琳。
我知道發生了什么事。 我們在配置文件中配置backends
的方式將確定如何將參數傳遞給后端的初始化。
例如:
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 \\ [])
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.