`Logger` handler factory for fallback if not bootstrapped
- 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
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