ErrorTrackerMixin mixin

Mixin that adds automatic error logging to any class via a Logger.

The default logger is a shared singleton. Override logger to inject a custom or pre-configured instance from the application layer.

Example:

class CheckoutService with ErrorTrackerMixin {
  @override
  Logger get logger => MyApp.logger;

  Future<void> purchase(Item item) {
    return guarded(() async {
      // any error here is automatically logged
      await _api.purchase(item);
    });
  }
}

Properties

hashCode int
The hash code for this object.
no setterinherited
logger Logger
The Logger used for all error tracking calls.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
trackerContext String
Context label embedded in log events. Defaults to the runtime type name.
no setter

Methods

guarded<T>(Future<T> body(), {bool fatal = false}) Future<T>
Runs body and automatically logs any thrown error.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
setupFlutterErrorTracking() → void
Installs global Flutter error handlers that forward all uncaught errors to logger.
toString() String
A string representation of this object.
inherited
trackError(Object error, {StackTrace? stackTrace, String? message, bool fatal = false}) Future<void>
Records an error to logger.
withTracking<T>(String action, Future<T> body(), {Map<String, dynamic>? params}) Future<T>
Runs body, logging action at LogLevel.info on entry.

Operators

operator ==(Object other) bool
The equality operator.
inherited