getsentry/sentry-apple-swiftybeaver
A SwiftyBeaver destination that forwards log entries to Sentry's structured logging system, automatically capturing application logs with full context including metadata, source location, and log levels.
Installation
Swift Package Manager
Add the following dependencies to your Package.swift or Xcode package dependencies:
dependencies: [
.package(url: "https://github.com/getsentry/sentry-apple-swiftybeaver", from: "9.0.0")
]Then add the SentrySwiftyBeaver product to your target:
.target(
name: "MyApp",
dependencies: [
.product(name: "SentrySwiftyBeaver", package: "sentry-apple-swiftybeaver")
]
)Quick Start
import Sentry
import SentrySwiftyBeaver
import SwiftyBeaver
SentrySDK.start { options in
options.dsn = "YOUR_DSN"
}
let log = SwiftyBeaver.self
let sentryDestination = SentryDestination()
log.addDestination(sentryDestination)
log.info("User logged in", context: ["userId": "12345", "sessionId": "abc"])Configuration
Log Level Threshold
SwiftyBeaver automatically filters log messages based on each destination's minLevel property. Set minLevel to control which messages are sent to Sentry.
let sentryDestination = SentryDestination()
sentryDestination.minLevel = .error
log.addDestination(sentryDestination)Log Level Mapping
SwiftyBeaver levels are automatically mapped to Sentry log levels:
| SwiftyBeaver Level | Sentry Log Level | | ------------------ | ---------------- | | .verbose | .trace | | .debug | .debug | | .info | .info | | .warning | .warn | | .error | .error | | .critical | .fatal | | .fault | .fatal |
Context Handling
The destination supports SwiftyBeaver's context parameter for additional metadata:
Dictionary Context
When context is provided as a [String: Any] dictionary, each key-value pair is added as an individual Sentry log attribute with the prefix swiftybeaver.context.{key}.
log.info("User action", context: [
"userId": "12345",
"action": "purchase",
"isActive": true,
"errorCode": 500,
"amount": 99.99
])Supported types in dictionary context:
- Strings
- Numbers (Int, Double, Float)
- Booleans
- Arrays (converted to string representation)
Non-Dictionary Context
For non-dictionary contexts, the entire context is converted to a string attribute swiftybeaver.context.
log.info("Test message", context: "simple string context")Automatic Attributes
The destination automatically includes the following attributes with every log entry:
sentry.origin:"auto.logging.swiftybeaver"swiftybeaver.level: The original SwiftyBeaver level (as raw value)swiftybeaver.thread: The thread identifiercode.file.path: The source file namecode.function.name: The function namecode.line.number: The line number
Documentation
License
This integration follows the same license as the Sentry Cocoa SDK. See the LICENSE file for details.
Package Metadata
Repository: getsentry/sentry-apple-swiftybeaver
Default branch: main
README: README.md