Route the SwiftLog 1.0 default log method to log(event:) - #503
Conversation
The two deprecated LogHandler defaults forwarded to each other, so a handler implementing only log(event:) overflowed the stack when called through the 1.0 entry point.
|
Pushed 700a794: the new tests passed #filePath and asserted the module derived from it, which is n/a on Windows where the path has no forward slash; they now pass a fixed POSIX path. The Android, macOS simulator and Wasm jobs fail the same way on main. |
|
Thank you for catching this! Indeed, using a |
|
Wrapper handlers. A multiplexing or filtering handler written before source: existed forwards to its inner handlers via log(level:message:metadata:file:function:line:). Here’s one: https://github.com/DeFrenZ/Thread-Demo/blob/718bc4daac4586e6c16c2f9cfd2af87845ad4d97/Log/Log/LogHandler%2BMultiplex.swift#L57. Put an event-only handler behind that and it recurses until the stack overflows. Compiles fine, dies at runtime. |
|
For the merge: the two red legs, Android SDK and Wasm nightly, fail the same way on main's last three runs (crtbegin_dynamic.o missing on the Android SDK image; a force-unwrap diagnostic under the nightly Wasm toolchain in StreamLogHandler.swift), so they are runner state rather than this change. |
Motivation:
The two deprecated
LogHandlerdefaults forward to each other: the source-carryinglog(level:message:metadata:source:file:function:line:)default callslog(event:), whose default calls the source-carrying method, and the SwiftLog 1.0log(level:message:metadata:file:function:line:)default calls the source-carrying method. A handler that implements onlylog(event:), as the protocol documentation asks, therefore recurses until the stack overflows whenever anything calls the 1.0 method on it. Handlers written against SwiftLog 1.0 that wrap another handler and forward through the 1.0 method reach this path.Differs from #248, where the handler implemented no log method at all.
Modifications:
The 1.0 default builds a
LogEventand callslog(event:)directly. The source is still the module derived fromfile, as before. Two tests inCompatibilityTest: the 1.0 method reaching an event-only handler (SIGSEGV atmainbefore the change) and reaching a source-only handler.Result:
A
LogHandlerimplementing onlylog(event:)can be called through every deprecated entry point. No source-breaking change; both deprecated defaults remain.Verified on Linux with Swift 6.1.2:
swift test -Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable(166 tests) andswift-format lint --stricton the changed files.Found by an automated audit loop (Claude); patch and description reviewed by me.