mirror of
https://github.com/apple/swift-log
synced 2026-11-23 03:44:22 +00:00
Replace the flat-parameter `log(level:message:metadata:source:file:function:line:)` method on `LogHandler` with `log(event: LogEvent)`, enabling forward-compatible evolution of the `LogHandler` interface without breaking existing handler implementations. ### Motivation: Changes to the `LogHandler` API require dance around creating new overloads, deprecating old overloads, which unnecessary bloats `LogHandler` protocol surface (like happened with the source: parameter). We have upcoming changes that would introduce new capabilities to the `LogHandler` protocol, for example https://forums.swift.org/t/proposal-slg-0003-standardized-error-metadata-via-logger-convenience/84518/35. It makes sense to introduce a single container structure for all the data associated with a log event before introducing any new overloads in `LogHandler` protocol. ### Modifications: - New struct `LogEvent` is added. - `LogHandler` protocol now has an additional `log(event: LogEvent)` method. - `Logger` is calling handler's `log(event: LogEvent)` method. ### Result: Further changes to the `LogEvent` with new information passed from the `Logger` to a `LogHandler` does not require changes in the `LogHandler` API. As a bonus, `LogEvent` makes `source` a computable variable, improving performance for log handlers who do not need the default source created based on the log file location.