setLogger static method
- @Deprecated('Use Logar.setLogger() instead. This method will be removed in a future version.')
- AmwalLoggerFunction logger
Sets a custom logger function for error handling.
This method allows you to replace the default logging behavior with a custom implementation that can integrate with external logging services or provide custom error handling logic.
Parameters:
logger
- The custom logger function to use
Usage
// Set custom logger for Sentry integration
AmwalLogger.setLogger((error, stackTrace) {
Sentry.captureException(error, stackTrace: stackTrace);
});
// Set custom logger for Firebase Crashlytics
AmwalLogger.setLogger((error, stackTrace) {
FirebaseCrashlytics.instance.recordError(error, stackTrace);
});
// Set custom logger for custom error handling
AmwalLogger.setLogger((error, stackTrace) {
// Custom error handling logic
if (error is PaymentException) {
handlePaymentError(error);
}
// Log to console for development
print('Error: $error');
});
Deprecation Notice
This method is deprecated. Use Logar.addCollector() for external logging service integration instead.
Best Practices
When setting a custom logger:
- Ensure the logger function is thread-safe
- Handle errors gracefully to prevent crashes
- Consider performance impact of logging operations
- Provide meaningful error context and categorization
Implementation
@Deprecated(
'Use Logar.setLogger() instead. This method will be removed in a future version.')
static void setLogger(AmwalLoggerFunction logger) {
_logger = logger;
}