Skip to content

Unify logging into single typed JSONL logger#9

Merged
waltoss merged 1 commit intomainfrom
refactor/unified-logger
Mar 31, 2026
Merged

Unify logging into single typed JSONL logger#9
waltoss merged 1 commit intomainfrom
refactor/unified-logger

Conversation

@waltoss
Copy link
Copy Markdown
Contributor

@waltoss waltoss commented Mar 31, 2026

Summary

Replace 3 separate logging mechanisms (CdpLogger, DaemonLogger, DEBUG_DAP env var) with a single unified structured logger that writes all sources to one JSONL file per session.

Before

  • 2 log files per session: <session>.cdp.log + <session>.daemon.log
  • 3 logging systems: CdpLogger (protocol traffic), DaemonLogger (app events), DEBUG_DAP=1 (DAP to stderr)
  • No type safety on log data — any object accepted
  • Confusing UX: dbg logs vs dbg logs --daemon to switch between files
  • No DAP file logging — only stderr passthrough
// Before: 3 different APIs
this.cdpLogger.logSend(id, method, params);
this.daemonLogger.info("child.spawn", "Spawned process", { pid });
if (DEBUG_DAP) process.stderr.write(`[DAP] ${msg}\n`);

After

  • 1 log file per session: <session>.log
  • 1 typed logger with scoped children: Logger<"cdp">, Logger<"dap">, Logger<"session">
  • Compile-time type safety via LogData<N, M> conditional type — known messages enforce exact data shapes, unknown messages accept Record<string, unknown>
  • Unified viewer: dbg logs --src cdp --level debug with colored output and custom formatters per (source, message) pair
  • DAP protocol logging to file (trace level)
// After: one API, typed per source
const log = rootLogger.child("session");
log.info("child.spawn", { pid: 1234 });  // ✓ typed — pid required

const cdp = rootLogger.child("cdp");
cdp.trace("send", { method: "Debugger.pause", id: 5 });  // ✓ typed
cdp.trace("send", { method: "Debugger.pause" });          // ✗ compile error — missing id
cdp.debug("custom", { anything: true });                   // ✓ open fallback

dbg logs output (with colors)

10:34:35.715 TRACE cdp      → Debugger.pause
10:34:35.727 TRACE cdp      ← Debugger.pause #5 ✓ (12ms)
10:34:35.728 TRACE cdp      ⚡ Debugger.paused
10:34:35.730 INFO  session   child.spawn pid=1234
10:34:35.731 INFO  session   state.change from=idle to=paused

Test plan

  • 531 tests pass (all existing tests)
  • Typecheck clean
  • Lint clean
  • Unit tests updated for new logger API
  • Integration tests verify CDP, session, and process lifecycle logging

🤖 Generated with Claude Code

Replace separate CdpLogger + DaemonLogger + DEBUG_DAP with a single
structured logger (src/logger/) that writes all sources to one JSONL
file per session. Typed schemas enforce data shapes at compile time
for known messages, with open fallback for ad-hoc logs.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@waltoss waltoss merged commit 84bbaf8 into main Mar 31, 2026
5 checks passed
@waltoss waltoss deleted the refactor/unified-logger branch March 31, 2026 09:16
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