简体   繁体   English

记录器不工作Elixir

[英]Logger not working Elixir

I am trying to use the Logger.debug/1 for my web-project. 我正在尝试将Logger.debug/1用于我的web项目。 I am unable to get past this error message even though I did make additions to the configuration file (config.exs) present in /myApp/config. 即使我确实添加了/ myApp / config中的配置文件(config.exs),我也无法通过此错误消息。

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

I added this particular configuration at the end. 我在最后添加了这个特定的配置。

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

I took help to make this addition from http://elixir-lang.org/docs/master/logger/Logger.html 我从http://elixir-lang.org/docs/master/logger/Logger.html获得了帮助

You need to add require Logger in your module definition, eg right after defmodule AAA... 您需要在模块定义中添加require Logger ,例如在defmodule AAA...

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

Got it ! 得到它了 ! The reason why it didn't work because Logger was not found in the same module. 它之所以不起作用是因为Logger没有在同一个模块中找到。 So one has to import the module and functions in-order to use them. 因此,必须导入模块和函数才能使用它们。

So I used 所以我用过

require Logger

and this solved the problem. 这解决了这个问题。 The program started working again. 该计划再次开始运作。

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

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