SwiftyBeaver for tvOS
Integrate SwiftyBeaver with Sentry to capture and send structured logs.
The SentrySwiftyBeaver package provides a SwiftyBeaver destination that forwards log entries to Sentry's structured logging system. Once configured, any logs emitted through SwiftyBeaver are automatically captured and sent to Sentry with full context, including metadata, source location, and log levels.
- Sentry Cocoa SDK
9.27.0or above - SwiftyBeaver
2.0.0or above
Add the package via Swift Package Manager:
dependencies: [
.package(url: "https://github.com/getsentry/sentry-apple-swiftybeaver", from: "9.0.0")
]
dependencies: [
.package(url: "https://github.com/getsentry/sentry-apple-swiftybeaver", from: "9.0.0")
]
Or add it in Xcode via File > Add Package Dependencies using the URL https://github.com/getsentry/sentry-apple-swiftybeaver.
By default, the integration uses precompiled Sentry binary xcframeworks. If you need to build Sentry from source, enable the SentryFromSource trait:
dependencies: [
.package(url: "https://github.com/getsentry/sentry-apple-swiftybeaver", from: "9.0.0", traits: ["SentryFromSource"])
]
dependencies: [
.package(url: "https://github.com/getsentry/sentry-apple-swiftybeaver", from: "9.0.0", traits: ["SentryFromSource"])
]
Initialize the Sentry SDK, then add SentryDestination to SwiftyBeaver. SDK 9.27.0+ doesn't require an enable flag for logs forwarded by this integration:
import Sentry
import SwiftyBeaver
import SentrySwiftyBeaver
SentrySDK.start { options in
options.dsn = "___PUBLIC_DSN___"
}
let log = SwiftyBeaver.self
let sentryDestination = SentryDestination()
log.addDestination(sentryDestination)
import Sentry
import SwiftyBeaver
import SentrySwiftyBeaver
SentrySDK.start { options in
options.dsn = "___PUBLIC_DSN___"
}
let log = SwiftyBeaver.self
let sentryDestination = SentryDestination()
log.addDestination(sentryDestination)
Use SwiftyBeaver's minLevel property on the destination to control which messages are sent to Sentry:
let sentryDestination = SentryDestination()
sentryDestination.minLevel = .error
log.addDestination(sentryDestination)
let sentryDestination = SentryDestination()
sentryDestination.minLevel = .error
log.addDestination(sentryDestination)
log.info("User logged in")
log.error("Payment failed")
log.warning("API rate limit approaching")
log.info("User logged in")
log.error("Payment failed")
log.warning("API rate limit approaching")
The destination supports SwiftyBeaver's context parameter for additional metadata.
When context is a [String: Any] dictionary, each key-value pair is added as an individual Sentry log attribute prefixed with swiftybeaver.context.:
log.info("User action", context: [
"userId": "12345",
"action": "purchase",
"amount": 99.99
])
// Produces attributes: swiftybeaver.context.userId, swiftybeaver.context.action, etc.
log.info("User action", context: [
"userId": "12345",
"action": "purchase",
"amount": 99.99
])
// Produces attributes: swiftybeaver.context.userId, swiftybeaver.context.action, etc.
For non-dictionary contexts, the value is converted to a single string attribute swiftybeaver.context:
log.info("Test message", context: "simple string context")
log.info("Test message", context: "simple string context")
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 |
The destination automatically includes the following attributes with every log entry:
| Attribute | Description |
|---|---|
sentry.origin | "auto.logging.swiftybeaver" |
swiftybeaver.level | The original SwiftyBeaver level (as raw value) |
swiftybeaver.thread | The thread identifier |
code.file.path | The source file path |
code.function.name | The function name |
code.line.number | The line number |
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").