Changes in config.exs -> No recompilation?

Hello,

When I just change something in config.exs (want to change the logging level) and then start mix run, elixir ... or iex -S mix my changes are not considered, so I assume, it hasn’t recompiled.
When I then change something in one of my modules, the changes of my config.exs file are considered.

Is this supposed to happen?

I am using Elixir 1.13.0

Edit: Maybe my config.exs isn’t read at all…

It is supposed to pick up but perhaps we have a bug. Do you have an example project? What is the change you are doing to your config?

EDIT: I did this:

  1. Created a new project with mix new foo
  2. Changed lib/foo.ex to do require Logger; Logger.debug "hello"
  3. Ran mix compile
  4. Created config/config.exs and added config :logger, level: :debug
  5. Ran mix compile

And I could see the relevant file was recompiled.

Furthermore, if you have other files, only lib/foo.exs (or any other file that mentions the Logger) should recompile.

2 Likes

Thank you.

Further I did:
6. Change the config.exs to config :logger, level: :error
7. mix compile

I still get “23:02:58.931 [debug] hello” as output in the console. What do I wrong?

How are you invoking this logger message? IEx? From tests?

1 Like

I hope I don’t waste your time.

I get
17:36:05.710 [debug] hello

from
mix compile (first call) or
elixir lib/foo.ex

but not from
iìex -S mix

(though my config.exs contains config :logger, level: :error)


When I put
Logger.debug("hello")
in the hello function and call hello() from outside the Foo module I also get

Erlang/OTP 24 [erts-12.1.4] [source] [64-bit] [smp:12:12] [ds:12:12:10] [async-threads:1] [jit]

Compiling 1 file (.ex)

17:47:09.856 [debug] hello
Interactive Elixir (1.12.3) - press Ctrl+C to exit (type h() ENTER for help)
1 Like

Oh, the logger configuration is only applied after your application is compiled. :slight_smile: So if you move it inside a function, and then you call said funciton inside iex -S mix, it should apply properly.

Next time posting the code will help find the root cause quicker. :slight_smile:

2 Likes

You may be interested in this recent forum thread:

1 Like

So if I change
config :logger, level: :debug
to
config :logger, level: :error
in config.exs and call recompile inside iex -S mix the usage of Logger.debug("hello") will always print “hello”?

One hour later: Aaaah, I think now i get it. This is because config.exs is elixir script, which is not compiled. So “recompile” won’t catch changes in config.exs. But when I change something in an .ex file, my elixir app will get recompiled and my changes in config.exs take effect.

So I am really sorry to have occupied your time.