Improve and customize logging output - #139
Open
AF-cgi wants to merge 3 commits into
Open
Conversation
Parsing errors and rendering warnings are currently written straight to the standard streams, which embedders cannot silence or route into their own logging system. Introduce LogSink, a package level sink holding the handler, and expose it as SwiftDraw.Log. The default handler writes info messages to standard output and everything else to standard error, so the output is unchanged. Log lives in the SwiftDraw module rather than being re-exported from SwiftDrawDOM: the DOM module is not a package product, so members of a type declared there are unreachable for clients building with MemberImportVisibility. Call sites still use print() and are migrated separately.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #139 +/- ##
==========================================
+ Coverage 88.91% 89.22% +0.31%
==========================================
Files 166 170 +4
Lines 13466 13715 +249
==========================================
+ Hits 11973 12237 +264
+ Misses 1493 1478 -15 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Replace every print() in SwiftDraw and SwiftDrawDOM with LogSink, so parsing errors, rendering warnings and the SF Symbol alignment insets reach Log.handler. Levels follow the existing streams: alignment insets are info and keep going to standard output, unsupported content is a warning and parsing and encoding failures are errors, both on standard error. The Warning: prefix now comes from the handler rather than the call site, so it is not duplicated when messages are routed into another logging system. Output of the command line tool is unchanged. Parsing error messages move into makeParsingErrorMessage so they can be tested without replacing the process wide handler. Tests that do replace it are collected in a single serialized suite, since suites otherwise run in parallel and overwrite each other's handler. The test covering the renderer warning is guarded by canImport(CoreGraphics): without it SVG.init(dom:options:) records the size and generates no commands, so there is no warning to observe. The command line tool still prints directly and is migrated separately.
Route the messages of the command line tool through the log handler and add --quiet, which installs a handler reporting failures only. Warnings, the alignment insets, the Created line and the help printed after a conversion failure are suppressed; failures keep going to standard error and the exit code is unchanged. Only --quiet is added, not --verbose: everything is already reported by default, so a verbose flag would have nothing to enable. Log.info, Log.warning and Log.error become public so the tool, the first client of the handler outside the library, needs no package internals. --quiet is parsed as part of the configuration, so it is only in effect once the arguments are valid. A usage error is reported either way.
AF-cgi
force-pushed
the
feature/log-handler
branch
from
August 27, 2026 09:20
d6b50d7 to
3c9bdda
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add
Log.handlerto control diagnostic outputMotivation
SwiftDraw writes diagnostics straight to the standard streams with
print()— 27 call sites, 20 in the library and 7 in the command line tool. None of them can be silenced or redirected, so an embedding tool gets[parsing error]on standard error for every element that fails to parse andAlignment:/Created:on standard output, mixed into its own output. Issue #59 is an example of this surfacing where it was not wanted.What this does
Adds
SwiftDraw.Log, a handler every message passes through:The command line tool gains
--quiet, which installsLog.standardStreams(minimumLevel: .error).Three commits: the handler, then the library call sites, then the tool.
Impact
mainin a worktree and diffed both binaries across five scenarios (gradient and filter warnings,--insets auto, malformed SVG, stroke-width override, missing file). stdout, stderr and the generated files are byte identical. The only difference in the tool's output is the new--quietline in the help.Configuration.logLevelhas a default value.import SwiftDraw.--quietsilences warnings,Created:, the alignment insets and the help dump that followed a failed conversion. Failures still go to stderr and the exit code is unchanged.18 new tests, suite green at 243.
Notes
Loglives in theSwiftDrawmodule rather thanSwiftDrawDOM. Declaring it in DOM and re-exporting it does not work for clients: DOM is not a package product, soMemberImportVisibilityhides every member and the import it suggests is unavailable. The storage is apackagetype in DOM that both modules emit through, withSwiftDraw.Logas the public facade.Only
--quietis added, not--verbose— everything is already reported by default, so a verbose flag would have nothing to enable.Two things I could easily change if you prefer:
Log.info/warning/errorare public so the tool needs no package internals, and--quietalso suppresses the SF SymbolAlignment:output, which is arguably program output rather than a diagnostic.