apple / apple/swift-log

Add a withLogged utility method

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

Description

As I wrap async throwing work in logs, I usually end up with a utility like this in every project:

```swift
func withLogged(
operation: String,
level: Logger.Level = .info,
_ work: () async throws -> Return
) async throws -> Return {
let logger = Logger.current
logger.log(level: level, "\(operation) starting")
do {
let result = try await work()
logger.log(level: level, "\(operation) finished successfully")
return result
} catch {
logger.log(level: level, "\(operation) failed", error: error)
throw error
}
}
```

Would it make sense to upstream here?

Contributor guide

Open the contributing guide

Research direction

Start by reviewing swift-log's existing Logger APIs and repository conventions, then assess where the proposed withLogged utility would belong. Done means the API and logging behavior are agreed for upstream inclusion and verified against the repository's relevant 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
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.