Timestamp log output - #5
Open
nanderss wants to merge 1 commit into
Open
Conversation
The log recorded only the order of events, not when they happened. That is not enough to diagnose an intermittent fault: a device that dropped twice in a minute and one that dropped twice in a day produce identical logs, and the difference is most of the diagnosis. Declare print at module scope so it shadows Swift.print. Every existing call site gains a timestamp without being modified, and new code gets it by default. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.
The log records the order of events but not when they happened, which isn't enough to diagnose anything intermittent.
I hit this chasing a deck that kept dropping off USB. The log showed:
repeated several times — but with no times attached, there was no way to tell whether that was a burst over a few seconds (suggesting a power or cable fault) or a slow drift over hours (suggesting something else entirely). Those need different investigations, and the log couldn't distinguish them. It turned out to be a failing USB hub, but only reseating hardware and watching it again established that.
With timestamps the same log answers the question directly:
Approach
Rather than touch ~30 call sites, this declares
printat module scope so it shadowsSwift.print. Every existing call gains a timestamp unmodified, and new code gets it by default. It's one new file and no changes to anything else.That shadowing is admittedly a slightly unusual technique — happy to switch to an explicit
log()function and update the call sites if you'd rather have something more obvious at the point of use. I went this way to keep the diff to a single file.Complements #2 (line-buffered stdout): that one makes the log appear at all under launchd, this one makes it possible to reason about. Independent commits, either can merge without the other.