Skip to content

Add SwiftLog LogHandler conformance to DiagnosticsLogger (#150) - #212

Open
elio-Wang wants to merge 1 commit into
AvdLee:mainfrom
elio-Wang:feature/swift-log-handler
Open

Add SwiftLog LogHandler conformance to DiagnosticsLogger (#150)#212
elio-Wang wants to merge 1 commit into
AvdLee:mainfrom
elio-Wang:feature/swift-log-handler

Conversation

@elio-Wang

Copy link
Copy Markdown
Contributor

What

Adds DiagnosticsLogger.SwiftLogHandler, a LogHandler conformance for apple/swift-log, so projects already using SwiftLog can bridge their logs into the Diagnostics report with a single bootstrap call:

try DiagnosticsLogger.setup()

LoggingSystem.bootstrap { label in

    DiagnosticsLogger.SwiftLogHandler(label: label)

} 

Resolves #150.

Changes

  • Package.swif — add apple/swift-log ≥ 1.6.0 dependency
  • DiagnosticsLogger.swift — make init() and standard public; add setup(_:) accepting a custom logger instance
  • SwiftLogHandler.swift (new) — LogHandler conformance; maps trace/debug/info/notice/warning → debug, error/critical → error
  • SwiftLogHandlerTests.swift (new) — tests for level mapping, metadata merging, and custom logger instances

Notes

  • @unchecked Sendable matches swift-log's own StreamLogHandler pattern — metadata / logLevel are set at bootstrap, not mutated across threads.
  • Diagnostics only has debug levels, so the mapping groups the lower SwiftLog levels into debug . Can be revisited if more levels are added later.

Allow DiagnosticsLogger to be used as a backing store for SwiftLog's
LoggingSystem by providing a DiagnosticsLogger.SwiftLogHandler type.
Projects already using SwiftLog can now seamlessly forward all log
messages into the Diagnostics report.

- Add swift-log as a package dependency
- Make DiagnosticsLogger.init() and .standard public
- Add setup(_:) overload accepting a custom logger instance
- Add DiagnosticsLogger.SwiftLogHandler nested LogHandler type
- Map SwiftLog levels to Diagnostics debug/error CSS classes
- Add unit tests for the SwiftLog integration

Resolves AvdLee#150
@elio-Wang
elio-Wang requested a review from AvdLee as a code owner July 27, 2026 02:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request: Conform DiagnosticLogger to SwiftLog LogHandler

1 participant