---
title: "SwiftyBeaver"
description: "Integrate SwiftyBeaver with Sentry to capture and send structured logs."
url: https://docs.sentry.io/platforms/apple/guides/macos/logs/swiftybeaver/
---

# SwiftyBeaver for macOS

The [`SentrySwiftyBeaver`](https://github.com/getsentry/sentry-apple-swiftybeaver) package provides a [SwiftyBeaver](https://github.com/SwiftyBeaver/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.

## [Requirements](https://docs.sentry.io/platforms/apple/guides/macos/logs/swiftybeaver.md#requirements)

* Sentry Cocoa SDK `9.27.0` or above
* SwiftyBeaver `2.0.0` or above

## [Install](https://docs.sentry.io/platforms/apple/guides/macos/logs/swiftybeaver.md#install)

Add the package via Swift Package Manager:

```swift
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`.

### [Building Sentry From Source](https://docs.sentry.io/platforms/apple/guides/macos/logs/swiftybeaver.md#building-sentry-from-source)

By default, the integration uses precompiled Sentry binary xcframeworks. If you need to build Sentry from source, enable the `SentryFromSource` trait:

```swift
dependencies: [
    .package(url: "https://github.com/getsentry/sentry-apple-swiftybeaver", from: "9.0.0", traits: ["SentryFromSource"])
]
```

## [Configure](https://docs.sentry.io/platforms/apple/guides/macos/logs/swiftybeaver.md#configure)

Initialize the Sentry SDK with logs enabled, then add `SentryDestination` to SwiftyBeaver:

```swift
import Sentry
import SwiftyBeaver
import SentrySwiftyBeaver

SentrySDK.start { options in
    options.dsn = "https://<key>@o<orgId>.ingest.sentry.io/<projectId>"
    options.enableLogs = true
}

let log = SwiftyBeaver.self
let sentryDestination = SentryDestination()
log.addDestination(sentryDestination)
```

### [Log Level Threshold](https://docs.sentry.io/platforms/apple/guides/macos/logs/swiftybeaver.md#log-level-threshold)

Use SwiftyBeaver's `minLevel` property on the destination to control which messages are sent to Sentry:

```swift
let sentryDestination = SentryDestination()
sentryDestination.minLevel = .error
log.addDestination(sentryDestination)
```

## [Verify](https://docs.sentry.io/platforms/apple/guides/macos/logs/swiftybeaver.md#verify)

```swift
log.info("User logged in")
log.error("Payment failed")
log.warning("API rate limit approaching")
```

## [Context Handling](https://docs.sentry.io/platforms/apple/guides/macos/logs/swiftybeaver.md#context-handling)

The destination supports SwiftyBeaver's `context` parameter for additional metadata.

### [Dictionary Context](https://docs.sentry.io/platforms/apple/guides/macos/logs/swiftybeaver.md#dictionary-context)

When `context` is a `[String: Any]` dictionary, each key-value pair is added as an individual Sentry log attribute prefixed with `swiftybeaver.context.`:

```swift
log.info("User action", context: [
    "userId": "12345",
    "action": "purchase",
    "amount": 99.99
])
// Produces attributes: swiftybeaver.context.userId, swiftybeaver.context.action, etc.
```

### [Non-Dictionary Context](https://docs.sentry.io/platforms/apple/guides/macos/logs/swiftybeaver.md#non-dictionary-context)

For non-dictionary contexts, the value is converted to a single string attribute `swiftybeaver.context`:

```swift
log.info("Test message", context: "simple string context")
```

## [Log Level Mapping](https://docs.sentry.io/platforms/apple/guides/macos/logs/swiftybeaver.md#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`         |

## [Automatic Attributes](https://docs.sentry.io/platforms/apple/guides/macos/logs/swiftybeaver.md#automatic-attributes)

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                                |
