【问题标题】:Logger not working Elixir记录器不工作 Elixir
【发布时间】:2015-11-26 08:41:56
【问题描述】:

我正在尝试将Logger.debug/1 用于我的网络项目。即使我确实对 /myApp/config 中存在的配置文件 (config.exs) 进行了添加,我也无法通过此错误消息。

** (CompileError) web/controllers/api/app_controller.ex:36: you must require Logger before invoking the macro Logger.debug/1

我在最后添加了这个特定的配置。

  config :logger,
    backends: [:console],
    compile_time_purge_level: :info

我从 http://elixir-lang.org/docs/master/logger/Logger.html 那里得到了帮助

【问题讨论】:

    标签: logging elixir phoenix-framework


    【解决方案1】:

    您需要在模块定义中添加require Logger,例如紧接着defmodule AAA...

    例如:https://github.com/22cans/exsyslog/blob/2b9ea2be7d7fcc17eab061425b6cd4fad8643996/examples/example1/lib/example1.ex

    【讨论】:

      【解决方案2】:

      知道了!之所以不起作用是因为在同一个模块中没有找到 Logger。因此,必须导入模块和函数才能使用它们。

      所以我用了

      require Logger
      

      这解决了问题。程序又开始工作了。

      【讨论】:

      • 我认为 Zepplock 的回答很好地涵盖了这一点。
      • 我同意@onoriocatenacci
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多