ConsoleLogStrategy class
A LogStrategy implementation that logs messages, errors, and fatal errors to the console.
This strategy provides a modern 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.
Features:
- Modern console formatting with colors and emojis
- Optional isolate-based processing (disabled by default for performance)
- Performance monitoring
- Structured output with context and events
Example:
var consoleStrategy = ConsoleLogStrategy(logLevel: LogLevel.info);
var logger = StrategicLogger(strategies: [consoleStrategy]);
logger.log("A simple log message.");
// Enable isolate for heavy formatting (optional)
var consoleWithIsolate = ConsoleLogStrategy(useIsolate: true);
- Inheritance
-
- Object
- LogStrategy
- ConsoleLogStrategy
Constructors
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
- useIsolate → bool
-
Whether this strategy should use isolates for heavy operations.
finalinherited
Methods
-
error(
LogEntry entry) → Future< void> -
Logs an error or a structured event with an error to the console.
override
-
fatal(
LogEntry entry) → Future< void> -
Marks an error as fatal and records it to the console.
override
-
info(
LogEntry entry) → Future< void> -
Logs a message or a structured event to the console.
override
-
log(
LogEntry entry) → Future< void> -
Logs a message or a structured event to the console.
override
-
logError(
dynamic error, StackTrace? stackTrace, LogEvent? event, Map< String, dynamic> ? context) → Future<void> -
Legacy method for logging errors (for backward compatibility).
inherited
-
logMessage(
dynamic message, LogEvent? event, Map< String, dynamic> ? context) → Future<void> -
Legacy method for logging messages (for backward compatibility).
inherited
-
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