Skip to content

Add Logger.add_handlers/1 #12412

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions lib/logger/lib/logger.ex
Original file line number Diff line number Diff line change
Expand Up @@ -319,11 +319,11 @@ defmodule Logger do

Each handler has the shape `{:handler, name, handler_module, config_map}`.
Once defined, a handler can be explicitly attached in your
`c:Application.start/2` callback:
`c:Application.start/2` callback with `add_handlers/1`:

:logger.add_handlers(:my_app)
Logger.add_handlers(:my_app)

You can also developer your own handlers. Erlang handlers run in the same
You can also develop your own handlers. Handlers run in the same
process as the process logging the message/event. This gives developers
flexibility but they should avoid performing any long running action in
such handlers, as it may slow down the action being executed considerably.
Expand Down Expand Up @@ -725,6 +725,20 @@ defmodule Logger do
:ok
end

@doc """
Adds the handlers configured in the `:logger` application parameter
of the given `app`.

This is used to register new handlers into the logging system.
See [the module documentation](#module-erlang-otp-handlers) for
more information.
"""
@doc since: "1.15.0"
@spec add_handlers(atom()) :: :ok | {:error, term}
def add_handlers(app) when is_atom(app) do
:logger.add_handlers(app)
end

@doc """
Adds a new backend.
"""
Expand Down