feat: persistent error logging for hook events#55
Merged
Conversation
Hook send-event failures (network errors, missing config, malformed
payloads) were previously swallowed: `fileLog` early-returned unless
`debug: true` was set, and the async subprocess discarded stderr. When
events stopped reaching the platform, there was no on-disk trace to
diagnose from.
This change introduces `internal/logger` — a small package with:
Error always written, regardless of config
Debug written only when SetDebug(true) has been called
Logs live at ~/.config/promptconduit/logs/promptconduit.log (XDG-aware)
and rotate at 1 MiB; only one backup is kept (~2 MiB cap per machine).
Wiring:
- cmd/hook.go: every failure path now calls logger.Error; trace lines
use logger.Debug; the legacy /tmp/promptconduit-hook.log helper is
removed.
- internal/client/api.go: the async subprocess inherits an fd pointing
at the log file as stderr, so a panic/crash that escapes the logger
still leaves a trace.
Plus a new `promptconduit logs` command with -n/--tail, --follow,
--path, and --clear flags.
Verified end-to-end on macOS:
- Successful send: DEBUG breadcrumbs only (debug=true config).
- Forced failure (bad API URL, debug=false): one ERROR line in the
log; no DEBUG noise.
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 bug
Hook send-event failures were silent.
fileLog(cmd/hook.go) early-returned unlessdebug: truewas set, the async subprocess setstderr = nil(internal/client/api.go), and even the existing debug-only log went to/tmp/promptconduit-hook.log— a path that's blown away on reboot and confusingly collides with the macOS app's own log file.Net effect: when events stopped reaching the platform (network blip, expired key, server 5xx), the user had no on-disk trace to diagnose from.
The fix
New
internal/loggerpackage:Error(format, args...)— always written, regardless of config.Debug(format, args...)— only written afterSetDebug(true)(the hook entry points call this from the loaded config).~/.config/promptconduit/logs/promptconduit.log(XDG-aware)..log.1backup; total footprint ≤ 2 MiB.clientpackage, so it's safe to call from anywhere including the hot hook path.Wiring:
cmd/hook.go: every failure path now callslogger.Error; trace lines uselogger.Debug; legacy/tmp/promptconduit-hook.logwriter removed.internal/client/api.go: the async subprocess now inherits a fd pointing at the log file asStderr, so a panic that escapes the in-process logger still leaves a trace.Plus a new
promptconduit logscommand:Verification
End-to-end on macOS:
Success path (debug=true config):
Failure path (bad API URL, debug=false in config):
Exactly one ERROR line, zero DEBUG noise. Goal achieved: silent failures are now loud, verbose tracing stays off unless explicitly enabled.
Test plan
go test ./internal/logger/— 5 tests pass (Error always writes, Debug gated, rotation at MaxBytes, Tail returns last N lines, Tail handles missing file)make test— full suite greengo vet ./...cleanpromptconduit logs --path,--clear,-n,--followall work--followfallback to polling kicks in whentailis absent🤖 Generated with Claude Code