Skip to content

Commit

Permalink
Restrict Logger.configure on config_change callback (#10388)
Browse files Browse the repository at this point in the history
The `config_change` callback is called from `application_controller` process,
which is receiving env updates on releases. `Logger.configure` does a blocking
call to the `Logger` process, which calls `Application.put_env`

This causes a crash on logger config update.

The fix is to call `Logger.configure` only for the config that have not yet
been persisted.
  • Loading branch information
hairyhum authored and josevalim committed Oct 3, 2020
1 parent e1cb898 commit b96fc39
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/logger/lib/logger/app.ex
Expand Up @@ -62,7 +62,9 @@ defmodule Logger.App do

@doc false
def config_change(changed, _new, _removed) do
Logger.configure(changed)
# All other config has already been persisted, we only need to
# update the level and reload the logger state.
Logger.configure(Keyword.take(changed, [:level]))
end

@doc """
Expand Down
3 changes: 2 additions & 1 deletion lib/logger/test/logger_test.exs
Expand Up @@ -647,7 +647,8 @@ defmodule LoggerTest do
:ok = Logger.configure(level: :debug)

try do
assert Logger.App.config_change([level: :error], [], []) === :ok
assert Application.put_env(:logger, :level, :error) === :ok
assert :application_controller.config_change(logger: [level: :debug]) === :ok
assert Logger.level() === :error
after
Logger.configure(level: :debug)
Expand Down

0 comments on commit b96fc39

Please sign in to comment.