error method
Logs an error or a structured event with an error to the console.
error
- The error to log.
stackTrace
- The stack trace associated with the error.
event
- An optional LogEvent providing additional context for the error.
Implementation
@override
Future<void> error(
{dynamic error, StackTrace? stackTrace, LogEvent? event}) async {
try {
if (shouldLog(event: event)) {
developer.log(
'>>═══════════════════════CONSOLELOG STRATEGY [ERROR]═══════════════════════>>',
name: 'ConsoleLogStrategy',
);
if (event != null) {
final ConsoleLogEvent consoleEvent = event as ConsoleLogEvent;
developer.log(
'eventName: ${consoleEvent.eventName} eventMessage: ${consoleEvent.eventMessage ?? "No message"} error: $error',
name: 'ConsoleLogStrategy',
error: error,
stackTrace: stackTrace,
);
} else {
developer.log('$error',
name: 'ConsoleLogStrategy', error: error, stackTrace: stackTrace);
}
developer.log(
'<<═══════════════════════CONSOLELOG STRATEGY [ERROR]═══════════════════════<<',
name: 'ConsoleLogStrategy',
);
}
} catch (e, stack) {
developer.log('Error during error handling in ConsoleLogStrategy: $e',
name: 'ConsoleLogStrategy', error: e, stackTrace: stack);
}
}