# \[Announcement\] swift-log-oslog: OSLog integration for swift-log

**URL:** <https://forums.swift.org/t/announcement-swift-log-oslog-oslog-integration-for-swift-log/90838>\
**Category:** Related Projects\
**Tags:** swift-log, oslog, darwin\
**Created:** [November 17, 2026, 10:35pm UTC](https://forums.swift.org/t/announcement-swift-log-oslog-oslog-integration-for-swift-log/90838 "2026-11-17T22:35:58Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![kukushechkin](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/kukushechkin/32/10940_2.png) [@kukushechkin](https://forums.swift.org/u/kukushechkin)\
**Post date:** [November 17, 2026, 10:35pm UTC](https://forums.swift.org/t/announcement-swift-log-oslog-oslog-integration-for-swift-log/90838/1 "2026-11-17T22:35:58Z")

</div>

Hi everyone,

We're excited to announce the initial release of [swift-log-oslog](https://github.com/apple/swift-log-oslog), a Swift Log backend that writes to OSLog.

[Swift Log](https://github.com/apple/swift-log) is the logging API, and backends decide where logs go. With `OSLogHandler`, anything that logs through `swift-log`, including your dependencies, is delivered to `OSLog`, so you can view it with the [Unified Logging tools](https://developer.apple.com/documentation/os/viewing-log-messages), like Console and the `log` command-line tool.

## What's in the package

- `OSLogHandler` is a `LogHandler` for the Darwin unified logging system, available on Apple platforms.
- `SensitivityAttribute` lets you mark each metadata value as `.public` or `.sensitive`. Swift Log is cross-platform and works everywhere swift-log does, including Linux, Windows, and WebAssembly.

This package is an alpha, and the API may change before 1.0. Feedback is welcome.

## Using OSLogHandler

Use `OSLogHandler` as your swift-log backend. To control which metadata values `OSLog` redacts, mark them with the `Sensitivity` attribute, which is based on the metadata value attributes of [SLG-0004](https://github.com/apple/swift-log/blob/main/Sources/Logging/Docs.docc/Proposals/SLG-0004-metadata-value-attributes.md).

`SensitivityAttribute` doesn't depend on `OSLog`, so code shared between macOS and Linux marks its metadata the same way. Where `OSLog` isn't available, `OSLogHandler` isn't either, so wrap any handler in `RedactionLogHandler` to redact the values that aren't tagged `.public`.

```swift
import Logging
import OSLogHandler
import SensitivityAttribute

let userId = "12345"

let logger = Logger(label: "auth") { label in
    #if canImport(os)
    OSLogHandler(subsystem: "com.example.myapp", category: label)
    #else
    RedactionLogHandler(wrapping: StreamLogHandler.standardOutput(label: label))
    #endif
}

logger.info("Login successful", metadata: [
    "user.id": "\(userId, sensitivity: .sensitive)",
    "action": "\("password", sensitivity: .public)",
])

```

In Console.app, this logs:

```swift
Login successful action=password <private>

```

If the system is configured to show private data, for example while you debug, the full message appears:

```swift
Login successful action=password user.id=12345

```

## Building on the community's work

Over the years, several packages have connected swift-log to `OSLog`. They proved that the need is real, and we're grateful to those authors for showing the way.

With swift-log-oslog, Apple is providing a fully supported version of this connection. Apple maintains `OSLog`, and we're committed to keeping this package in step with it and with swift-log. As either one evolves, the package will follow, and problems in the integration are ours to fix.

Development happens on GitHub, where issues and pull requests are welcome. Changes to the public API go through a short proposal process modeled on the one swift-log uses.

## Getting started

Add the package to your `Package.swift`:

```swift
.package(url: "https://github.com/apple/swift-log-oslog", exact: "0.1.0")

```

Then add the products you need to your target:

```swift
.product(name: "OSLogHandler", package: "swift-log-oslog")
.product(name: "SensitivityAttribute", package: "swift-log-oslog")

```

The documentation is available on the Swift Package Index. Please report bugs and ask questions on [GitHub](https://github.com/apple/swift-log-oslog/issues), and see `CONTRIBUTING.md` if you'd like to contribute. We look forward to your feedback.

Vladimir

---

<div class="post-metadata">

**Author:** ![FlorianPircher](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/florianpircher/32/39919_2.png) [@FlorianPircher](https://forums.swift.org/u/FlorianPircher)\
**Post date:** [November 18, 2026, 10:37am UTC](https://forums.swift.org/t/announcement-swift-log-oslog-oslog-integration-for-swift-log/90838/2 "2026-11-18T10:37:07Z")

</div>

As I understand it, the OSLog functions get some special treatment from the compiler to be more efficient and that special handling is undone by wrapping those APIs. Is this assumption correct, and if so, how does this package deal with that?

---

<div class="post-metadata">

**Author:** ![kukushechkin](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/kukushechkin/32/10940_2.png) [@kukushechkin](https://forums.swift.org/u/kukushechkin)\
**Post date:** [November 18, 2026, 11:26am UTC](https://forums.swift.org/t/announcement-swift-log-oslog-oslog-integration-for-swift-log/90838/3 "2026-11-18T11:26:37Z")

</div>

@FlorianPircher `OSLog` performance optimizations in the Swift compiler are only applied for const message format strings and indeed won't be applied for the `LogHandler` wrapping `OSLog`.

This packages includes a couple of benchmarks for various patterns of using `Logger` and `OSLog`. I recommend checking them while making a decision which API to use, or if it is worth having a compilation condition choosing between explicit `OSLog` on Darwin and Swift Log on other platforms.

---

<div class="post-metadata">

**Author:** ![saagarjha](https://avatars.discourse-cdn.com/v4/letter/s/85f322/32.png) [@saagarjha](https://forums.swift.org/u/saagarjha)\
**Post date:** [November 20, 2026, 7:27am UTC](https://forums.swift.org/t/announcement-swift-log-oslog-oslog-integration-for-swift-log/90838/4 "2026-11-20T07:27:33Z")

</div>

> [@kukushechkin](#):
>
> Over the years, several packages have connected swift-log to `OSLog`. They proved that the need is real, and we're grateful to those authors for showing the way.

Do you have more detail you can share about this need? I have looked at some of these packages in the past but to me it always seemed more like they seemed to just fill a perceived hole without a careful consideration of what is required to bridge the strengths of each design. If we can find something that does this it would be great to have it officially supported but I am concerned that the implementation might build be building a footgun-as-a-service because it provides an attractive way to do something that just should not be supported. I think with a better understanding of what the attraction _is_ we might find that this could end up showing that the problem is better solved at a layer that's not a Swift package, for example.

---

<div class="post-metadata">

**Author:** ![0xTim](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/0xtim/32/27968_2.png) [@0xTim](https://forums.swift.org/u/0xTim)\
**Post date:** [November 20, 2026, 12:08pm UTC](https://forums.swift.org/t/announcement-swift-log-oslog-oslog-integration-for-swift-log/90838/5 "2026-11-20T12:08:12Z")

</div>

> [@saagarjha](#):
>
> Do you have more detail you can share about this need?

I'm a package author that writes packages that work across all platforms. OSLog is not a Swift library, it's an Apple library. Therefore I use `swift-log` to send log messages in my package `SuperCoolPackage` and an end user can decide on whatever backend they want.

I'm an application developer and I want to use `SuperCoolPackage` but I want logs from that package to be emitted alongside logs from my application that I log out. If I use the OSLog backend for `swift-log` then it 'all just works' ™

---

<div class="post-metadata">

**Author:** ![FranzBusch](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/franzbusch/32/19447_2.png) [@FranzBusch](https://forums.swift.org/u/FranzBusch)\
**Post date:** [November 20, 2026, 2:53pm UTC](https://forums.swift.org/t/announcement-swift-log-oslog-oslog-integration-for-swift-log/90838/6 "2026-11-20T14:53:13Z")

</div>

What Tim said is how I see this as well. There are two different audiences of Swift developers:

- Cross-platform Swift developers
- Apple-platform app developers

Both have different needs. Most importantly, the first group needs to adapt at runtime to the platform they deploy on. Not only for logging but for many other things as well. I often refer to these as our platform plugin points. Some other ones are:

- Concurrency executors
- Metrics and tracing
- Compression and decompression
- Cryptography
- Configuration and secret stores
- Network configuration such as TLS or DNS

If you develop a package for one specific platform, such as Apple platforms, it is best to use the platform technologies directly. They will generally give you the best behavior and performance. When developing cross-platform code, the choice is between conditionalizing the code or introducing an abstraction that lets the final executable configure which "backend" to use. Conditionalizing doesn't work in practice since it requires every single package to do it, and what we have seen is that packages just end up creating their own internal abstractions.

An abstraction is almost always going to cost something unless it is expressed as a generic and the code gets specialized. For logging that would mean a lot of code suddenly becomes generic over a `Logger`, which isn't feasible either. So the minimum cost we have to pay for the abstraction is going through an existential. With `swift-log` and the new `OSLog` backend we pay quite a bit more than that today, because `OSLog` has two special behaviors:

- The format string of a log message is emitted as static data into the binary. A log record only references the static data meaning the message is never copied, you can filter on it, and you can audit every statement a binary can log just by inspecting it.
- Nothing is formatted when you log. The arguments are copied into a compact binary buffer together with their type and privacy, and formatting only happens when someone reads the logs, e.g. in `Console.app` or with `log show`.

`swift-log` can't preserve either of these today. The message is an interpolated string and metadata values are effectively strings, so the handler has to format everything up front and pass it to `OSLog` as dynamic arguments behind a few generic format strings.

On the other hand, `swift-log` has capabilities that `OSLog` doesn't have. The most important one is metadata that accumulates dynamically along the call stack, either by passing a logger down or through task locals. This is invaluable in distributed systems, where you attach a request or trace ID once and every log line from every library handling that request carries it.

We should look at this release as a first step. We know many people have built these backends, and we wanted to provide an official one that we can evolve together with `swift-log`. However, we are definitely interested in bringing `swift-log` and `OSLog` closer together so that we get all of these capabilities with the maximum performance.

* * *

Over the past months, I have been prototyping in this direction, and the results are encouraging. The core idea is that log messages and metadata keys are static, and only the values are dynamic. With that and a bit of macro support, everything that is known at compile time can go into the binary as static data. Roughly like this:

```swift
enum LoggingKeys {
    @LogMetadataKey("request.id", privacy: .public)
    static var id: LogKey<String>
}

var logger = logger
logger[LoggingKeys.id] = request.id
#log(logger, .info, "routing request", .string("http.path", request.path, .public))

```

This puts each statement's format string into the binary, e.g. `routing request http.path=%s`. It also puts every metadata key across the whole dependency graph there, together with its module, type and privacy level into the binary. That gives us back the auditing and filtering `OSLog` offers, and it also works for the metadata that accumulates along the call stack. Values stay typed and unformatted until a backend needs them, so `OSLog` gets the format it expects and structured backends get the right types. In my early measurements this produces the same records as `os.Logger` at the same cost, while still working with any backend. Importantly, none of this is ready for a proposal yet, but it's the direction I'd like us to explore.
