captureMessage method

Future<SentryId> captureMessage(
  1. String? message, {
  2. SentryLevel? level,
  3. String? template,
  4. List? params,
  5. dynamic hint,
  6. ScopeCallback? withScope,
})

Captures the message.

Implementation

Future<SentryId> captureMessage(
  String? message, {
  SentryLevel? level,
  String? template,
  List<dynamic>? params,
  dynamic hint,
  ScopeCallback? withScope,
}) async {
  var sentryId = SentryId.empty();

  if (!_isEnabled) {
    _options.logger(
      SentryLevel.warning,
      "Instance is disabled and this 'captureMessage' call is a no-op.",
    );
  } else if (message == null) {
    _options.logger(
      SentryLevel.warning,
      'captureMessage called with null parameter.',
    );
  } else {
    final item = _peek();
    final scope = _cloneAndRunWithScope(item.scope, withScope);

    try {
      sentryId = await item.client.captureMessage(
        message,
        level: level,
        template: template,
        params: params,
        scope: scope,
        hint: hint,
      );
    } catch (err) {
      _options.logger(
        SentryLevel.error,
        'Error while capturing message with id: $message, error: $err',
      );
    } finally {
      _lastEventId = sentryId;
    }
  }
  return sentryId;
}