Skip to content

Commit

Permalink
Merge pull request #274 from Automattic/lantean/new-public-api
Browse files Browse the repository at this point in the history
CrashLogging: New Error Logging API
  • Loading branch information
crazytonyli authored Dec 18, 2023
2 parents dc4405b + 43fa374 commit 3c0988d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ _None._

_None._

## 3.2.0

- CrashLogging new API that supports logging Errors with Tag/Value

## 3.1.0

### New Features
Expand Down
22 changes: 22 additions & 0 deletions Sources/Remote Logging/Crash Logging/CrashLogging.swift
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,29 @@ public class CrashLogging {
// MARK: - Manual Error Logging
public extension CrashLogging {

/// Writes the error to the Crash Logging system, and includes a stack trace. This API supports for rich events.
/// By setting a Tag/Value pair, you'll be able to filter these events, directly, with the `has:` operator (Sentry Web Interface).
///
/// - Parameters:
/// - error: The error object
/// - tags: Tag Key/Value pairs to be set in the Error's Scope
/// - level: The level of severity to report in Sentry (`.error` by default)
func logError(_ error: Error, tags: [String: String], level: SentryLevel = .error) {

let event = Event.from(
error: error as NSError,
level: level
)

SentrySDK.capture(event: event) { scope in
for (key, value) in tags {
scope.setTag(value: value, key: key)
}
}

dataProvider.didLogErrorCallback?(event)
}

/// Writes the error to the Crash Logging system, and includes a stack trace.
///
/// - Parameters:
Expand Down

0 comments on commit 3c0988d

Please sign in to comment.