NAME
Sentry::Integration::Logging - Base class of the logging integrations
SYNOPSIS
# Breadcrumbs from warn on, events from fatal on
Sentry::SDK->init({
integrations => [
Sentry::Integration::MojoLog->new(level => 'warning', event_level => 'fatal'),
Sentry::Integration::Log4perl->new(event_level => 'error'),
],
});
# Nothing of these loggers
Sentry::Integration::Logging->ignore_logger('My::Noisy::*');
DESCRIPTION
The logging integrations (Sentry::Integration::MojoLog, Sentry::Integration::Log4perl) record what the application logs, like sentry-python's logging integration: messages from "level" on as breadcrumbs (type log, category the logger's name), messages from "event_level" on as events (logger and logentry set), and with "enable_logs" in Sentry::SDK messages from "logs_level" on as Sentry logs. The event of a message comes before its breadcrumb, so it does not contain it.
Only messages at a level the logger's configuration enables are recorded; thresholds and filters of single outputs (e.g. Log4perl appenders) are not taken into account. What the logger writes, $! and $? stay as they are.
Sentry groups the events by their message, which is the text as logged: messages with variable parts (ids, names) open an issue each. Log stable text, or put the variable parts into an exception, tags or the scope.
A message carrying an exception is reported as that exception (mechanism logging), with the message as logentry: an exception object passed to the logger, or text ending with the message of an exception thrown recently, e.g. $log->error("Request failed: $@"). If that exception was captured already, e.g. by Mojolicious::Plugin::SentrySDK, which Mojolicious logs as well, the message is no event of its own, only a breadcrumb; an exception reported by a log message is not reported again when it ends the program. Text carries an exception if it is or ends with the message of one, and that message names the place perl added (at FILE line N.); messages ending with a newline count only as they are, so that "connect timeout\n" is not taken for a "timeout\n" thrown before.
Logging and dying in one (Log4perl's logdie, logcroak, logconfess, error_die) records the message as breadcrumb only, also from "event_level" on: the exception is the event, captured once by Sentry::Integration::DieHandler or the framework integration if no eval catches it. Not so for LOGDIE of Log4perl's easy mode, which cannot be told apart from FATAL, nor with :no_extra_logdie_message, which makes logdie exit instead of die.
ATTRIBUTES
See "ATTRIBUTES" in Sentry::Integration::Base, and:
level
The severity (debug, info, warning, error, fatal) from which on messages become breadcrumbs. Default: info. undef records none.
event_level
The severity from which on messages become events. Default: undef, none, as in sentry-python 3: errors reach Sentry as the exceptions the die handler and the framework integrations capture, log messages are the breadcrumbs leading to them. Set it to error to send logged errors as well.
logs_level
The severity from which on messages are sent as Sentry logs (see "LOGS" in Sentry::SDK) with the option "enable_logs" in Sentry::SDK, default info, like the level of sentry-python's logging integration. undef sends none. The logs have the level of the message (warn for warning), the message as body and the attributes logger.name (the category of the breadcrumbs) and sentry.origin (the integration's "origin" in Sentry::Integration::Base).
METHODS
new
my $integration = Sentry::Integration::MojoLog->new(level => 'warning');
Takes the attributes above. A threshold that is no severity is reported with a warning and records nothing.
ignore_logger
Sentry::Integration::Logging->ignore_logger('My::Noisy');
Sentry::Integration::Logging->ignore_logger('My::Noisy::*');
Records no messages of loggers with this name, for all logging integrations; * matches any text. Names are those of the breadcrumbs' category.
unignore_logger
Sentry::Integration::Logging->unignore_logger('My::Noisy');
Undoes "ignore_logger" of the same pattern.
setup
Takes "enable_logs" in Sentry::SDK from the options of the client, see "setup" in Sentry::Integration::Base.
wants
return $orig->(@args) if !$integration->wants('debug');
For logging integrations: whether a message of the severity would be recorded, to do no work for others.
record
$integration->record($logger_name, $severity, \@parts, $separator,
$breadcrumb_only);
For logging integrations: records a message the logger wrote. @parts are what the application passed the logger, which joins them with $separator. With $breadcrumb_only (the logger dies after the message), it is no event. Failures are logged, never thrown.