log method
Logs a message or a structured event to Firebase Crashlytics.
If an event is provided, the log will include structured data tailored for Firebase Crashlytics. Otherwise, it logs a general message.
message
- a general message to log if no event is provided.
event
- an optional LogEvent providing structured data for logging.
Implementation
@override
Future<void> log({dynamic message, LogEvent? event}) async {
try {
if (shouldLog(event: event)) {
developer.log(
'Logging to Firebase Crashlytics',
name: 'FirebaseCrashlyticsLogStrategy',
);
if (event != null) {
if (event is FirebaseCrashlyticsLogEvent) {
FirebaseCrashlytics.instance
.log('${event.eventName}: ${event.eventMessage}');
}
} else {
FirebaseCrashlytics.instance.log('Message: $message');
}
}
} catch (e, stack) {
developer.log(
'Error during logging in Firebase Crashlytics Strategy',
name: 'FirebaseCrashlyticsLogStrategy',
error: e,
stackTrace: stack,
);
}
}