Skip to content

Timestamp log output - #5

Open
nanderss wants to merge 1 commit into
okoker:mainfrom
nanderss:timestamped-logging
Open

Timestamp log output#5
nanderss wants to merge 1 commit into
okoker:mainfrom
nanderss:timestamped-logging

Conversation

@nanderss

Copy link
Copy Markdown

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:

Device disconnected, waiting for reconnect...
Sent icon for lcd_1 (3801 bytes)
...
Device connected
Device disconnected, waiting for reconnect...

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:

[2026-08-19 12:37:39] LCD icons committed
[2026-08-19 12:37:39] Device connected

Approach

Rather than touch ~30 call sites, this declares print at module scope so it shadows Swift.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.

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>
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.

1 participant