Skip to content

Structured Logging and TUI Debug Overlay#21

Merged
JasonWarrenUK merged 1 commit into
mainfrom
feat/structured-logging
May 3, 2026
Merged

Structured Logging and TUI Debug Overlay#21
JasonWarrenUK merged 1 commit into
mainfrom
feat/structured-logging

Conversation

@JasonWarrenUK
Copy link
Copy Markdown
Owner

Structured Logging and TUI Debug Overlay

Overview

Adds structured logging throughout the application using charmbracelet/log, with all output directed to ~/.wyrd/wyrd.log. A new TUI debug overlay (:log command) lets you inspect the log without leaving the app.

Summary

Previously, Wyrd was the strong, silent type — things happened and nobody talked about it. Now it keeps a diary at ~/.wyrd/wyrd.log, meticulously recording every node write, edge deletion, and git push like a particularly conscientious butler. And if you want to read the butler's notes, just type :log in the command palette and a monocle-shaped viewport materialises before your eyes.

Tip

No steps required after pulling. The logger initialises automatically; log file is created on first run. Use --log-level debug for verbose output.


Changes

LG.1: Add charmbracelet/log dependency
  • go.mod / go.sum: Added github.com/charmbracelet/log v1.0.0 as a direct dependency.
LG.2: Initialise logger in main.go
  • cmd/wyrd/main.go: Added PersistentPreRunE that creates ~/.wyrd/ and opens ~/.wyrd/wyrd.log (O_CREATE|O_WRONLY|O_APPEND, 0644). Creates a charmbracelet/log.New(file) logger stored in a package-level appLogger var.
  • internal/tui/app.go: Added Logger *clog.Logger field to Config and logger field to Model.
LG.3: --log-level flag and WYRD_LOG_LEVEL env var
  • cmd/wyrd/main.go: Added --log-level persistent flag. Env var WYRD_LOG_LEVEL is the fallback; flag takes precedence. Maps "debug"/"info"/"warn"/"error" to the corresponding log levels.
LG.4: Thread logger through store
  • internal/store/store.go: Added type Option func(*Store) and WithLogger(*clog.Logger) Option. Changed New(path, clock) to New(path, clock, ...Option). Added nil-guarded logDebug/logWarn helpers.
  • internal/store/node.go: Debug logging in WriteNode and ArchiveNode.
  • internal/store/edge.go: Debug logging in WriteEdge and DeleteEdge.
  • internal/store/watcher.go: Replaced log/slog with the store's nil-guarded logger.
LG.5: Thread logger through sync
  • internal/sync/git.go: Added *clog.Logger parameter to Sync(). Debug logging for git commands, info for completion, error for failures. Nil-guarded helper functions.
  • internal/cli/sync.go: Added Logger field to SyncOptions, passed through to sync.Sync().
LG.6: Thread logger through query engine
  • internal/query/engine.go: Added type EngineOption func(*Engine) and WithLogger. Changed NewEngine(index, maxDepth) to accept ...EngineOption. Debug logging for query text and row count.
LG.7: TUI debug overlay
  • internal/tui/log_overlay.go: New file. logOverlay struct with Open/Close/Update/View methods. Reads last 100 lines from ~/.wyrd/wyrd.log into a viewport. Esc/q to close, scroll keys forwarded to viewport.
  • internal/tui/palette.go: Registered :log command in builtinCommands().
  • internal/tui/app.go: Added logOverlay field to Model. Wired :log command via openLogOverlayMsg. Composited overlay in View() using NewLayer/NewCompositor (same pattern as palette). Input routing when overlay is active.

- Add charmbracelet/log dependency (LG.1)
- Initialise logger in PersistentPreRunE writing to ~/.wyrd/wyrd.log (LG.2)
- Add --log-level flag and WYRD_LOG_LEVEL env var fallback (LG.3)
- Thread logger through store via functional options (LG.4)
- Thread logger through sync via direct parameter (LG.5)
- Thread logger through query engine via functional options (LG.6)
- Add TUI debug overlay toggled via :log command (LG.7)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@JasonWarrenUK JasonWarrenUK merged commit 6af8b38 into main May 3, 2026
@JasonWarrenUK JasonWarrenUK deleted the feat/structured-logging branch May 3, 2026 18:39
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