LogStrategy class abstract

An abstract class that represents a logging strategy.

This class provides the structure for implementing various logging strategies, allowing for detailed control over how messages, errors, and fatal errors are logged depending on their level and the events they are associated with.

New implementations (v1.4.0+): Override log(), info(), error(), and fatal() methods that receive a complete LogEntry object with context.

Legacy implementations: Override logMessage() and logError() methods for backward compatibility. These methods now receive context automatically.

Example (new way):

class MyStrategy extends LogStrategy {
  @override
  Future<void> log(LogEntry entry) async {
    // Use entry.message, entry.context, entry.event, etc.
  }
}

Example (legacy way - still works):

class MyLegacyStrategy extends LogStrategy {
  @override
  Future<void> logMessage(dynamic message, LogEvent? event, Map<String, dynamic>? context) async {
    // context is now available automatically!
  }
}
Implementers

Constructors

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

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 pair
logLevel LogLevel
The minimum log level that this strategy handles for logging.
getter/setter pair
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 pair

Methods

error(LogEntry entry) Future<void>
Logs an error.
fatal(LogEntry entry) Future<void>
Logs a fatal error.
info(LogEntry entry) Future<void>
Logs an info message or event.
log(LogEntry entry) Future<void>
Logs a message or event.
logError(dynamic error, StackTrace? stackTrace, LogEvent? event, Map<String, dynamic>? context) Future<void>
Legacy method for logging errors (for backward compatibility).
logMessage(dynamic message, LogEvent? event, Map<String, dynamic>? context) Future<void>
Legacy method for logging messages (for backward compatibility).
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.
toString() String
Provides a string representation of the strategy including its type and log level.
override

Operators

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