apple / apple/swift-log

`Logger` handler factory for fallback if not bootstrapped

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

Description

As a maintainer of a package using swift-log, we want to make an implementation such that _if_ the logging system hasn't been bootstrapped by package clients, _then_ our loggers will use some specific log handler (an OS handler implementation in our case).

I think the API itself would be a bit simple on the `Logger`s itself, but can foresee ambiguity issues with the trailing closure. I admit I'm also unsure about the performance of making the bootstrap checks, but ultra-fast performance isn't a large concern within our package.

```swift
struct Logger {
init(label: String, ifNotBootstrappedFactory: (String) -> any LogHandler)
}
```

---

Or, if the `LoggingSystem` somehow exposed its own, but newly separate and optional, `factory` instance we would be able to check within the existing local `factory` inits, just an idea.

```swift
let logger = Logger(label: "mylogger") { label in
if let bootstrapped = LoggingSystem.factory {
return bootstrapped(label)
} else {
return MyLogHandler(label)
}
}
```

Contributor guide

Open the contributing guide

Research direction

Start by reading the existing Logger initializer and LoggingSystem factory APIs, focusing on how bootstrapping and handler creation currently work. Clarify the fallback factory semantics, closure behavior, and performance expectations before proposing an API; done means an agreed design that lets package authors select a handler when logging has not been bootstrapped.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.