apple / apple/swift-log

Better OSLog integration

Open
#482 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
Swift
Stars
4k
Forks
344
Avg merge
1d 15h
Merged PRs (30d)
4

Description

I think this library could benefit from a deeper OSLog integration. Specifically in the area of low-overhead, potentially compiler-integrated logging.

We have an internal library used for audio analysis and we run it on iOS, macOS, and server-side. Choosing a logging system for this is kind of tough: (1) OSLog is great, but Apple-only; (2) swift-log is great, but using an OSLog backend gives up a lot of the benefits of OSLog (it is specifically recommended to never wrap OSLog); (3) `#if canImport(OSLog) … #else … #endif` everywhere - this is a deeply suboptimal developer experience but does end up with the benefits of both libraries (as long as the logging doesn’t drift apart!).

Benefits of OSLog which are lost with an OSLog backend:
1. Extremely low overhead logging so we can e.g. log in the hot-path of our audio analysis without everything becoming intolerably slow (back in the NSLog days this was a problem for us). These are done with in-compiler special handling, which IMO should be an option for this library.
2. Signposting (https://developer.apple.com/documentation/os/ossignposter) which is a wildly useful performance tool on Apple platforms. I don’t know that this is necessarily a goal for this library.
3. Go-to-log-source in Xcode logging pane

Benefits of OSLog which an OSLog backend helps with:
1. Unified system log - we can, e.g., inspect the logging output of a release build very easily on Apple systems
2. Built-in API for querying logs (e.g. for customer support scenarios). I don’t think this should be a goal for this library.

This evolved from a conversation on Slack: https://swift-open-source.slack.com/archives/CN4BCMN8Z/p1782498000391199

And I also filed FB23477196 for Apple folk.

Contributor guide

Open the contributing guide

Research direction

Start by reviewing the current swift-log API and its OSLog backend, then compare the low-overhead, compiler-integrated requirements described here with the cross-platform constraints. Done would require an agreed, concrete scope and acceptance criteria for the proposed integration; this issue does not name files or tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
observability-sre
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.