View Source Sentry.LoggerBackend (Sentry v10.10.0)
An Elixir Logger backend that reports logged messages and crashes to Sentry.
:loggerhandlerThis module will eventually become legacy. Elixir
Loggerbackends will eventually be deprecated in favor of Erlang:loggerhandlers.Sentry already has a
:loggerhandler,Sentry.LoggerHandler. In new projects and wherever possible, useSentry.LoggerHandlerin 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
})
:loggerhandlerIn new projects, try to use
Sentry.LoggerHandlerrather than thisLoggerbackend. Elixir will likely deprecateLoggerbackends in the future in favor of:loggerhandlers, 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:metadatakey can be set to a list of keys. Metadata under those keys will be added in the:extracontext under the:logger_metadatakey. Defaults to[]. If set to:all, all metadata will be included.:allis available since v9.0.0 of this library.:level- The minimum Logger level 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