getsentry/sentry-apple-cocoalumberjack
A CocoaLumberjack logger that forwards log entries to Sentry's structured logging system, automatically capturing application logs with full context including source location, thread information, 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-cocoalumberjack", from: "9.0.0")
]Then add the SentryCocoaLumberjack product to your target:
.target(
name: "MyApp",
dependencies: [
.product(name: "SentryCocoaLumberjack", package: "sentry-apple-cocoalumberjack")
]
)Quick Start
import Sentry
import SentryCocoaLumberjack
import CocoaLumberjackSwift
SentrySDK.start { options in
options.dsn = "YOUR_DSN"
}
DDLog.add(SentryCocoaLumberjackLogger(), with: .info)
DDLogInfo("User logged in")
DDLogError("Payment failed")
DDLogWarn("API rate limit approaching")
DDLogDebug("Processing request")
DDLogVerbose("Detailed trace information")Configuration
Log Level Threshold
Use CocoaLumberjack's built-in filtering API when adding the logger to set the minimum log level for messages to be sent to Sentry:
// Only send error logs to Sentry
DDLog.add(SentryCocoaLumberjackLogger(), with: .error)Log Level Mapping
CocoaLumberjack log levels are automatically mapped to Sentry log levels:
| CocoaLumberjack Level | Sentry Log Level | | --------------------- | ---------------- | | .error | .error | | .warning | .warn | | .info | .info | | .debug | .debug | | .verbose | .trace |
Automatic Attributes
The logger automatically includes the following attributes with every log entry:
sentry.origin:"auto.logging.cocoalumberjack"cocoalumberjack.level: The original CocoaLumberjack log level (error, warning, info, debug, verbose)code.file.path: The source file namecode.function.name: The function namecode.line.number: The line numbercocoalumberjack.context: The log context (integer)cocoalumberjack.timestamp: The log timestampcocoalumberjack.threadID: The thread IDcocoalumberjack.threadName: The thread name (if available)cocoalumberjack.queueLabel: The dispatch queue label (if available)
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-cocoalumberjack
Default branch: main
README: README.md