简体   繁体   中英

Logger not working Elixir

I am trying to use the Logger.debug/1 for my web-project. 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.

** (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

You need to add require Logger in your module definition, eg right after defmodule AAA...

For example: 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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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