log method

  1. @override
Future<void> log({
  1. dynamic message,
  2. LogEvent? event,
})
override

Logs a message or a structured event to Sentry.

If an event is provided, the log will include structured data tailored for Sentry. 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 Sentry',
        name: 'SentryLogStrategy',
      );
      if (event != null && event is SentryLogEvent) {
        Sentry.captureMessage('${event.eventName}: ${event.eventMessage}');
      } else {
        Sentry.captureMessage('Message: $message');
      }
    }
  } catch (e, stack) {
    developer.log(
      'Error during logging in Sentry Strategy',
      name: 'SentryLogStrategy',
      error: e,
      stackTrace: stack,
    );
  }
}