This function should be used by custom Logger handlers to make configuration consistent no matter which handler the system uses. Normal usage is to add a call to logger:add_handlers/1
just after the processes that the handler needs are started, and pass the application's logger
configuration as the argument. For example:
-behaviour(application).
start(_, []) ->
case supervisor:start_link({local, my_sup}, my_sup, []) of
{ok, Pid} ->
ok = logger:add_handlers(my_app),
{ok, Pid, []};
Error -> Error
end.
This reads the logger
configuration parameter from the my_app
application and starts the configured handlers. The contents of the configuration use the same rules as the logger handler configuration
.
If the handler is meant to replace the default handler, the Kernel's default handler have to be disabled before the new handler is added. A sys.config
file that disables the Kernel handler and adds a custom handler could look like this:
[{kernel,
[{logger,
%% Disable the default Kernel handler
[{handler, default, undefined}]}]},
{my_app,
[{logger,
%% Enable this handler as the default
[{handler, default, my_handler, #{}}]}]}].