1.5.0
版本发布时间: 2023-01-18 15:42:15
apple/swift-log最新发布版本:1.6.1(2024-06-25 01:37:08)
Changes
Swift version support
This release drops support for Swift 5.0.
Swift 5.1+ remain supported for the time being.
Logger.MetadataProvider
This release introduces metadata providers!
They are an additional way to add metadata to your log statements automatically whenever a log statement is about to be made. This works extremely well with systems like distributed tracing, that may pick up trace identifiers and other information from the task-local context from where the log statement is being made.
The feature came with a swift evolution style proposal introduction to the "why?" and "how?" of this feature you may find interesting.
Metadata providers are used like this:
import Logging
enum Namespace {
@TaskLocal static var simpleTraceID: String?
}
let simpleTraceIDMetadataProvider = Logger.MetadataProvider {
guard let traceID = Namespace.simpleTraceID else {
return [:]
}
return ["simple-trace-id": .string(traceID)]
}
LoggingSystem.bootstrap({ label, metadataProvider in
myCoolLogHandler(label: label, metadataProvider: metadataProvider)
}, metadataProvider: simpleTraceIDMetadataProvider)
which in turn makes every Logger
on this LoggingSystem
add this contextual metadata to log statements automatically:
let log = Logger(label: "hello")
Namespace.$simpleTraceID.withValue("1234-5678") {
test()
}
func test() {
log.info("test log statement")
}
// [info] [simple-trace-id: 1234-5678] test log statement
Adoption in LogHandler
s
In order to support this new feature in your log handlers, please make it accept a MetadataProvider?
at creation, and store it as:
struct MyHandler: LogHandler {
// ...
public var metadataProvider: Logger.MetadataProvider?
// ...
}
What's Changed
Highlight
- Metadata Providers (e.g. for Distributed Tracing) in LogHandlers by @ktoso in https://github.com/apple/swift-log/pull/238
Other changes
- [docs] Minimal docc setup and landing page by @ktoso in https://github.com/apple/swift-log/pull/226
- =docc Make docs use symbol references by @ktoso in https://github.com/apple/swift-log/pull/230
- =docc Move to multiple Package.swift files by @ktoso in https://github.com/apple/swift-log/pull/231
- Undo 5.7 package files, not needed yet by @ktoso in https://github.com/apple/swift-log/pull/232
- Update README: Add missing Source param by @Rusik in https://github.com/apple/swift-log/pull/233
- Fix build for wasm by @ahti in https://github.com/apple/swift-log/pull/236
- Add .spi.yml for Swift Package Index DocC support by @yim-lee in https://github.com/apple/swift-log/pull/240
- Fixes link to Supabase repository in README.md by @timobollwerk in https://github.com/apple/swift-log/pull/245
New Contributors
- @Rusik made their first contribution in https://github.com/apple/swift-log/pull/233
- @ahti made their first contribution in https://github.com/apple/swift-log/pull/236
- @timobollwerk made their first contribution in https://github.com/apple/swift-log/pull/245
Full Changelog: https://github.com/apple/swift-log/compare/1.4.4...1.5.0