Skip to content

Logger never gets out of :discard mode #9028

Closed
@epsylonix

Description

@epsylonix

Environment

Erlang/OTP 21
Elixir 1.8.1

Current behavior

When the message queue size exceeds the discard threshold Logger enters into the discard mode with a message like that:

Logger has 661 messages in its queue, which is above :discard_threshold. Messages will be discarded until the message queue goes back to 75% of the threshold size

From that moment on all log messages are discarded until the app is restarted

> pid = :erlang.whereis(Logger)           
> Process.info(pid, :message_queue_len)   

{:message_queue_len, 0}

> :sys.get_state(pid)                  
[
  {LoggerFileBackend, :file,
   %{...}},
  {Logger.Config, false,
   {%{
      level: :debug,
      mode: :discard,
      translators: [{Logger.Translator, :translate}],
      truncate: 8096,
      utc_log: false
    },
    %{
      async_threshold: 15,
      discard_threshold: 500,
      keep_threshold: 375,
      sync_threshold: 20
    }}}
]

> require Logger
> Logger.info("test")
# nothing is logged

# manually change logger mode
> st =  :ets.lookup_element(Logger.Config, :data, 2)
%{
level: :debug,
mode: :discard,
translators: [{Logger.Translator, :translate}],
truncate: 8096,
utc_log: false
}

> st = %{st | mode: :async}
> :ets.update_element(Logger.Config, :data, {2, st})

# now logging resumes

I believe I found what the problem is.
Logger's mode is updated when a new event arrives here:
https://github.com/elixir-lang/elixir/blob/v1.8/lib/logger/lib/logger/config.ex#L78-L102

But when Logger enters the :discard mode, all log messages are dropped and no event get generated:
https://github.com/elixir-lang/elixir/blob/v1.8/lib/logger/lib/logger.ex#L672-L678

So it seems that after entering a :discard mode Logger can't get out of it and all the log messages are dropped.

Expected behavior

After the Logger's message queue gets under the discard threshold Logger's mode should be updated appropriately.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions