ConsoleLogStrategy class

A LogStrategy implementation that logs messages, errors, and fatal errors to the console.

This strategy provides a simple way to output log information directly to the console, suitable for development and troubleshooting purposes. It supports distinguishing between general log messages, errors, and fatal errors, and can handle structured LogEvent instances if provided.

Example:

var consoleStrategy = ConsoleLogStrategy(logLevel: LogLevel.info);
var logger = StrategicLogger(strategies: [consoleStrategy]);
logger.log("A simple log message.");
Inheritance

Constructors

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

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>
Logs an error or a structured event with an error to the console.
override
fatal({dynamic error, StackTrace? stackTrace, LogEvent? event}) Future<void>
Marks an error as fatal and records it to the console.
override
log({dynamic message, LogEvent? event}) Future<void>
Logs a message or a structured event to the console.
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