error abstract method
Logs an error for failures and exceptions.
Error messages represent failures that impact functionality, such as network failures or unexpected exceptions that require investigation. Implementations should send errors to remote monitoring (Sentry) for production debugging.
The message describes what failed. The optional error and stackTrace
identify the caught exception. The extras map may include additional
context such as request payloads or application state at the time of failure.
Example:
try {
await placeOrder();
} catch (e, stackTrace) {
logger.error(
'Failed to place order',
error: e,
stackTrace: stackTrace,
extras: {'orderId': '789'},
);
}
Implementation
void error(String message, {Object? error, StackTrace? stackTrace, Map<String, Object?>? extras});