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.
Recommended (v4.0.0+): Override only handleLog() for uniform handling:
class MyStrategy extends LogStrategy {
@override
Future<void> handleLog(LogEntry entry) async {
// Use entry.message, entry.mergedContext, entry.event, etc.
print('${entry.level}: ${entry.message}');
}
}
Per-level handling: Override log(), info(), error(), and fatal()
for different behavior per log level.
Constructors
-
LogStrategy({LogLevel loggerLogLevel = LogLevel.none, LogLevel logLevel = LogLevel.none, List<
LogEvent> ? supportedEvents, bool useIsolate = true}) - 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
- useIsolate → bool
-
Whether this strategy should use isolates for heavy operations.
final
Methods
-
error(
LogEntry entry) → Future< void> - Logs an error.
-
fatal(
LogEntry entry) → Future< void> - Logs a fatal error.
-
handleLog(
LogEntry entry) → Future< void> - Main log handler - override this single method for uniform handling of all log levels.
-
info(
LogEntry entry) → Future< void> - Logs an info message.
-
log(
LogEntry entry) → Future< void> - Logs a debug or general message.
-
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