diff --git a/README.md b/README.md index b73ba66e..08b30821 100644 --- a/README.md +++ b/README.md @@ -54,23 +54,11 @@ More information on why this may be necessary can be found here: https://github. 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). -To set this up, add `{:ok, _} = Logger.add_backend(Sentry.LoggerBackend)` to your application's start function. Example: - ```diff - # lib/my_app/application.ex - # ... - def start(_type, _opts) do - children = [ - supervisor(MyApp.Repo, []), - supervisor(MyAppWeb.Endpoint, []) - ] - - opts = [strategy: :one_for_one, name: MyApp.Supervisor] - -+ {:ok, _} = Logger.add_backend(Sentry.LoggerBackend) +# config/config.exs - Supervisor.start_link(children, opts) - end ++ config :logger, ++ backends: [:console, Sentry.LoggerBackend] ``` The backend can also be configured to capture Logger metadata, which is detailed [here](https://hexdocs.pm/sentry/Sentry.LoggerBackend.html). diff --git a/lib/sentry/logger_backend.ex b/lib/sentry/logger_backend.ex index e2d3ffb4..cfef615a 100644 --- a/lib/sentry/logger_backend.ex +++ b/lib/sentry/logger_backend.ex @@ -4,26 +4,16 @@ defmodule Sentry.LoggerBackend do crashed processes. It replaces the previous `Sentry.Logger` sytem. To include the backend in your application, the backend can be added in your - application file: + configuration file: - def start(_type, _opts) do - children = [ - supervisor(MyApp.Repo, []), - supervisor(MyAppWeb.Endpoint, []) - ] - - opts = [strategy: :one_for_one, name: MyApp.Supervisor] - - {:ok, _} = Logger.add_backend(Sentry.LoggerBackend) - - Supervisor.start_link(children, opts) - end + config :logger, + backends: [:console, Sentry.LoggerBackend] If you are on OTP 21+ and would like to configure the backend to include metadata from `Logger.metadata/0` in reported events, it can be enabled: - {:ok, _} = Logger.add_backend(Sentry.LoggerBackend) - Logger.configure_backend(Sentry.LoggerBackend, include_logger_metadata: true) + config :logger, Sentry.LoggerBackend, + include_logger_metadata: true It is important to be aware of whether this will include sensitive information in Sentry events before enabling it.