Logger.add_backend
add_backend
, go back to Logger module for more information.
Specs
add_backend(backend(), keyword()) :: Supervisor.on_start_child()
Adds a new backend.
Adding a backend calls the init/1
function in that backend
with the name of the backend as its argument. For example,
calling
Logger.add_backend(MyBackend)
will call MyBackend.init(MyBackend)
to initialize the new
backend. If the backend's init/1
callback returns {:ok, _}
,
then this function returns {:ok, pid}
. If the handler returns
{:error, :ignore}
from init/1
, this function still returns
{:ok, pid}
but the handler is not started. If the handler
returns {:error, reason}
from init/1
, this function returns
{:error, {reason, info}}
where info
is more information on
the backend that failed to start.
Backends added by this function are not persisted. Therefore if the Logger application or supervision tree is restarted, the backend won't be available. If you need this guarantee, then configure the backend via the application environment:
config :logger, :backends, [MyBackend]
Options
:flush
- whentrue
, guarantees all messages currently sent toLogger
are processed before the backend is added
Examples
{:ok, _pid} = Logger.add_backend(MyBackend, flush: true)