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
Elixir provides Logger for logging in Elixir applications. Using Elixir Logger is only a little more effort than that, but it’s much more elegant and flexible. As well as being useful for debugging, logging can also provide you with more – and better structured – information about the state and health of your application.
Open the config.exs file, which is the boss of your app configuration and locate the config :logger line. Take a brief look at these lines. This is Elixir’s Logger configuration. Whatever you change here, is going to be applied to all your app’s logs. Start by changing the default log level of the entire app.
IO.puts (:stderr, "This is an error...") IO.inspect (self ()) This is the simplest form of logging in Elixir. The puts function takes two arguments, the first being the target destination of the log message (as an atom) and the second, the message itself.
Elixir programmers will often use IO.inspect/2 (guilty!) in their code as a quick and convenient debugging tool. Elixir provides Logger for logging in Elixir applications. Using Elixir Logger is only a little more effort than that, but it’s much more elegant and flexible.
You need to add require Logger
in your module definition, e.g. 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With