AmwalLogger class
Legacy AmwalLogger class - now integrated with Logar.
This class maintains backward compatibility while leveraging the new Logar logging system underneath. It provides a bridge between the old logging API and the new, more powerful Logar system.
Features
- Backward Compatibility: Maintains existing API for legacy code
- Logar Integration: Uses the new Logar system for actual logging
- Custom Logger Support: Allows custom logging implementations
- Multiple Log Levels: Support for error, info, debug, and warning
- Context Support: Rich logging with tags and additional data
Deprecation Notice
This class is deprecated and should not be used for new code. Use Logar directly for better performance and features.
Migration Path
// Old way (deprecated)
AmwalLogger.logError(error, stackTrace);
// New way (recommended)
Logar.error('Error message', error: error, stackTrace: stackTrace);
Usage Example
// Set custom logger for external services
AmwalLogger.setLogger((error, stackTrace) {
Sentry.captureException(error, stackTrace: stackTrace);
});
// Log errors with context
AmwalLogger.logErrorWithContext(
message: 'Payment processing failed',
error: exception,
stackTrace: stackTrace,
tag: 'PAYMENT',
data: {'transactionId': '123', 'amount': 100.0},
);
// Log different message types
AmwalLogger.logInfo('Payment initiated', tag: 'PAYMENT');
AmwalLogger.logDebug('Processing payment request', tag: 'PAYMENT');
AmwalLogger.logWarning('Payment taking longer than expected', tag: 'PAYMENT');
Log Levels
The logger supports multiple log levels:
- Error: Critical errors that need immediate attention
- Warning: Issues that may cause problems but aren't critical
- Info: General information about application flow
- Debug: Detailed information for development and debugging
Custom Logging
You can set a custom logger function to:
- Send logs to external services (Sentry, Firebase, etc.)
- Implement custom error handling logic
- Integrate with monitoring and alerting systems
- Provide backward compatibility for existing integrations
- Annotations
-
- @Deprecated('Use Logar directly instead. This class will be removed in a future version.')
Constructors
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
logDebug(
String message, {String? tag, Map< String, dynamic> ? data}) → void - Logs a debug message using Logar.
-
logError(
dynamic error, StackTrace? stackTrace) → void - Logs an error using the configured logger function.
-
logErrorWithContext(
{required String message, dynamic error, StackTrace? stackTrace, String? tag, Map< String, dynamic> ? data}) → void - Logs an error with additional context using Logar.
-
logInfo(
String message, {String? tag, Map< String, dynamic> ? data}) → void - Logs an informational message using Logar.
-
logWarning(
String message, {String? tag, Map< String, dynamic> ? data}) → void - Logs a warning message using Logar.
-
setLogger(
AmwalLoggerFunction logger) → void - Sets a custom logger function for error handling.