SentryLogStrategy class

A LogStrategy implementation that logs messages and errors to Sentry.

This strategy provides the functionality to send log messages and detailed error reports, including stack traces, to Sentry. It can be configured with a specific log level and can handle both general log messages and structured LogEvent instances tailored for Sentry.

The strategy distinguishes between general messages, errors, and fatal errors, ensuring that each type of log is appropriately reported to Sentry.

Example:

var sentryStrategy = SentryLogStrategy(
  logLevel: LogLevel.error,
);
var logger = StrategicLogger(strategies: [sentryStrategy]);
logger.error('Example error', stackTrace: StackTrace.current);
Inheritance

Constructors

SentryLogStrategy({LogLevel logLevel = LogLevel.none, List<LogEvent>? supportedEvents})
Constructs a SentryLogStrategy.

Properties

hashCode int
The hash code for this object.
no setterinherited
loggerLogLevel LogLevel
The log level set by the logger using this strategy. Used to determine if a message should be logged.
getter/setter pairinherited
logLevel LogLevel
The minimum log level that this strategy handles for logging.
getter/setter pairinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
supportedEvents List<LogEvent>?
A list of specific LogEvent types that this strategy supports. If null, all events are considered supported.
getter/setter pairinherited

Methods

error({dynamic error, StackTrace? stackTrace, LogEvent? event}) Future<void>
Records an error or a structured event with an error to Sentry.
override
fatal({dynamic error, StackTrace? stackTrace, LogEvent? event}) Future<void>
Marks an error as fatal and records it to Sentry.
override
log({dynamic message, LogEvent? event}) Future<void>
Logs a message or a structured event to Sentry.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
shouldLog({LogEvent? event}) bool
Determines whether a log operation should proceed based on the event and log level.
inherited
toString() String
Provides a string representation of the strategy including its type and log level.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited