Skip to content

Commit b571ddb

Browse files
committed
Update Logger backend recommendations
1 parent 877b3d9 commit b571ddb

File tree

1 file changed

+15
-26
lines changed

1 file changed

+15
-26
lines changed

lib/logger/lib/logger.ex

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -289,31 +289,24 @@ defmodule Logger do
289289
290290
The initial backends are loaded via the `:backends` configuration,
291291
which must be set before the `:logger` application is started.
292-
Backends can also be added dynamically through `add_backend/2`.
292+
However, it preferred to add and remove backends via `add_backend/2`
293+
the `remove_backend/2` function. This is often done in your
294+
`c:Application.start/2` callback:
293295
294-
For example, to add multiple backends to your application, modify your
295-
configuration:
296+
@impl true
297+
def start(_type, _args) do
298+
Logger.add_backend(MyCustomBackend)
296299
297-
config :logger,
298-
backends: [:console, MyCustomBackend]
299-
300-
Multiple instances of the same backend can be specified by adding tuples
301-
in the format `{BackendModuleName, :backend_name}`:
300+
The backend can be configured either on the `add_backend/2` call:
302301
303-
config :logger,
304-
backends: [
305-
:console,
306-
{MyCustomBackend, :error_backend},
307-
{MyCustomBackend, :debug_backend}
308-
]
302+
@impl true
303+
def start(_type, _args) do
304+
Logger.add_backend(MyCustomBackend, some_config: ...)
309305
310-
config :logger, :error_backend,
311-
level: :error
312-
# other options
306+
Or in your config files:
313307
314-
config :logger, :debug_backend,
315-
level: :debug
316-
# other options
308+
config :logger, MyCustomBackend,
309+
some_config: ...
317310
318311
### Elixir custom backends
319312
@@ -413,12 +406,8 @@ defmodule Logger do
413406
responsibility to implement it
414407
415408
The good news is that developers can use third-party implementations of
416-
both Elixir backends and Erlang handlers.
417-
418-
Elixir backends can be configured directly under the `:logger` application
419-
in your `config/config.exs`:
420-
421-
config :logger, backends: [ACustomBackend]
409+
both Elixir backends and Erlang handlers. We have already covered Elixir
410+
backends, so let's see how to add Erlang/OTP handlers.
422411
423412
Erlang/OTP handlers must be listed under your own application:
424413

0 commit comments

Comments
 (0)