Skip to content

Commit 1d4f3ab

Browse files
Merge pull request #379 from getsentry/logger-backend-docs
update docs to recommend Application environment for adding Logger backend
2 parents a567542 + 36d3bae commit 1d4f3ab

File tree

2 files changed

+8
-30
lines changed

2 files changed

+8
-30
lines changed

README.md

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -54,23 +54,11 @@ More information on why this may be necessary can be found here: https://github.
5454

5555
This library comes with an extension to capture all error messages that the Plug handler might not. This is based on [Logger.Backend](https://hexdocs.pm/logger/Logger.html#module-backends).
5656

57-
To set this up, add `{:ok, _} = Logger.add_backend(Sentry.LoggerBackend)` to your application's start function. Example:
58-
5957
```diff
60-
# lib/my_app/application.ex
61-
# ...
62-
def start(_type, _opts) do
63-
children = [
64-
supervisor(MyApp.Repo, []),
65-
supervisor(MyAppWeb.Endpoint, [])
66-
]
67-
68-
opts = [strategy: :one_for_one, name: MyApp.Supervisor]
69-
70-
+ {:ok, _} = Logger.add_backend(Sentry.LoggerBackend)
58+
# config/config.exs
7159

72-
Supervisor.start_link(children, opts)
73-
end
60+
+ config :logger,
61+
+ backends: [:console, Sentry.LoggerBackend]
7462
```
7563

7664
The backend can also be configured to capture Logger metadata, which is detailed [here](https://hexdocs.pm/sentry/Sentry.LoggerBackend.html).

lib/sentry/logger_backend.ex

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,16 @@ defmodule Sentry.LoggerBackend do
44
crashed processes. It replaces the previous `Sentry.Logger` sytem.
55
66
To include the backend in your application, the backend can be added in your
7-
application file:
7+
configuration file:
88
9-
def start(_type, _opts) do
10-
children = [
11-
supervisor(MyApp.Repo, []),
12-
supervisor(MyAppWeb.Endpoint, [])
13-
]
14-
15-
opts = [strategy: :one_for_one, name: MyApp.Supervisor]
16-
17-
{:ok, _} = Logger.add_backend(Sentry.LoggerBackend)
18-
19-
Supervisor.start_link(children, opts)
20-
end
9+
config :logger,
10+
backends: [:console, Sentry.LoggerBackend]
2111
2212
If you are on OTP 21+ and would like to configure the backend to include metadata from
2313
`Logger.metadata/0` in reported events, it can be enabled:
2414
25-
{:ok, _} = Logger.add_backend(Sentry.LoggerBackend)
26-
Logger.configure_backend(Sentry.LoggerBackend, include_logger_metadata: true)
15+
config :logger, Sentry.LoggerBackend,
16+
include_logger_metadata: true
2717
2818
It is important to be aware of whether this will include sensitive information
2919
in Sentry events before enabling it.

0 commit comments

Comments
 (0)