View Source Sentry.LoggerBackend (Sentry v10.8.0)
An Elixir Logger
backend that reports logged messages and crashes to Sentry.
:logger
handlerThis module will eventually become legacy. Elixir
Logger
backends will eventually be deprecated in favor of Erlang:logger
handlers.Sentry already has a
:logger
handler,Sentry.LoggerHandler
. In new projects and wherever possible, useSentry.LoggerHandler
in favor of this backend.
To include in your application, start this backend in your application start/2
callback:
# lib/my_app/application.ex
def start(_type, _args) do
Logger.add_backend(Sentry.LoggerBackend)
Sentry context will be included in metadata in reported events. Example:
Sentry.Context.set_user_context(%{
user_id: current_user.id
})
:logger
handlerIn new projects, try to use
Sentry.LoggerHandler
rather than thisLogger
backend. Elixir will likely deprecateLogger
backends in the future in favor of:logger
handlers, which would lead to us eventually removing this backend.
Configuration
:excluded_domains
- Any messages with a domain in the configured list will not be sent. Defaults to[:cowboy, :bandit]
to avoid double reporting events fromSentry.PlugCapture
.:metadata
- To include non-Sentry Logger metadata in reports, the:metadata
key can be set to a list of keys. Metadata under those keys will be added in the:extra
context under the:logger_metadata
key. Defaults to[]
. If set to:all
, all metadata will be included.:all
is available since v9.0.0 of this library.:level
- The minimum [Logger level](https://hexdocs.pm/logger/Logger.html#module-levels to send events for. Defaults to:error
.:capture_log_messages
- Whentrue
, this module will send all Logger messages. Defaults tofalse
, which will only send messages with metadata that has the shape of an exception and stacktrace.
Example:
config :logger, Sentry.LoggerBackend,
# Also send warning messages
level: :warning,
# Send messages from Plug/Cowboy
excluded_domains: [],
# Include metadata added with `Logger.metadata([foo_bar: "value"])`
metadata: [:foo_bar],
# Send messages like `Logger.error("error")` to Sentry
capture_log_messages: true