Is it possible to disable the default logger console

Hello,

It seems that it is not possible to disable the console logger backend once it is started:

iex(6)> Logger.debug("hello")

17:34:41.773 [debug] hello
:ok
iex(7)> LoggerBackends.remove :console
{:error, :not_found}
iex(8)> Logger.remove_backend :console
{:error, :not_found}
iex(9)> Supervisor.which_children LoggerBackends.Supervisor
[]
iex(10)> Logger.debug("hello")

17:35:04.995 [debug] hello
:ok
iex(11)> Logger.remove_backend Logger.Backends.Console
{:error, :not_found}
iex(12)> LoggerBackends.remove Logger.Backends.Console
{:error, :not_found}
iex(13)> Logger.debug("hello")

17:36:07.573 [debug] hello
:ok
iex(14)> LoggerBackends.remove LoggerBackends.Console
{:error, :not_found}
iex(15)> Logger.debug("hello")

17:40:23.171 [debug] hello

My team uses a library that configures our custom logger when that library application starts. The library attempts to remove the default console backend and add its own backend.

But it does not work, and we see duplicated logs, once with our format and once with the console format.

So I know that I can just set backends: [] in prod.exs but I fear that we could lose messages during startup. Is there a way to swap the backends at runtime?

Thank you.

3 Likes

It seems that

:logger.remove_handler(:default)

does the job :wink:

1 Like

Nice, thank you !

1 Like