Skip to content

Commit 17ffa85

Browse files
Merge pull request #472 from josevalim/patch-1
Use Logger.add_backend/1
2 parents 0b7f8e3 + d922c35 commit 17ffa85

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,13 @@ defmodule MyAppWeb.ErrorView do
9393

9494
### Capture Crashed Process Exceptions
9595

96-
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).
96+
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). You can add it as a backend when your application starts:
9797

9898
```diff
99-
# config/config.exs
99+
# lib/my_app/application.ex
100100

101-
+ config :logger,
102-
+ backends: [:console, Sentry.LoggerBackend]
101+
+ def start(_type, _args) do
102+
+ Logger.add_backend(Sentry.LoggerBackend)
103103
```
104104

105105
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: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
defmodule Sentry.LoggerBackend do
22
@moduledoc """
33
Report Logger events like crashed processes to Sentry. To include in your
4-
application, add this module to your Logger backends:
4+
application, start this backend in your application `start/2` callback:
55
6-
config :logger,
7-
backends: [:console, Sentry.LoggerBackend]
6+
# lib/my_app/application.ex
7+
def start(_type, _args) do
8+
Logger.add_backend(Sentry.LoggerBackend)
89
910
Sentry context will be included in metadata in reported events. Example:
1011

0 commit comments

Comments
 (0)