Skip to content

[Bug] debug logger has no size rotation or retention policy #411

@samzong

Description

@samzong

Problem

logger.ts writes all events to a daily-rotated file debug-YYYY-MM-DD.ndjson, but there is no size cap within a single day and no retention policy for old days. Two concrete problems:

  1. Unbounded daily file size — during a high-volume day (reconnect storms, development sessions), a single day's log file can grow to hundreds of MB or more. There is no rotation once it gets large.
  2. No retention — once the date rolls over, the previous day's file is left on disk untouched forever. Over a year of daily use, the user accumulates 365+ ndjson files under app.getPath('logs'), silently consuming disk.

Location

File: packages/desktop/src/main/debug/logger.ts:95-98

function currentFilePath(): string {
  const day = new Date().toISOString().slice(0, 10);
  return join(options.debugDir, `debug-${day}.ndjson`);
}

Fix Approach

Add two bounds:

  1. Size-based rotation within a day: track the current file size; when it exceeds a threshold (e.g. 50 MB), rotate to debug-YYYY-MM-DD.1.ndjson, .2.ndjson, etc.
  2. Age-based cleanup: on logger init, scan options.debugDir for files matching debug-*.ndjson, parse the date from the filename, and delete files older than N days (e.g. 14 days). Keep it simple — no need for a full retention library.

Both should be configurable via CreateDebugLoggerOptions so tests can disable them.

Verification

  1. Run pnpm check — must pass.
  2. Unit test for the filename parser + age filter logic.
  3. Manual: set a low rotation threshold (e.g. 10 KB), write enough events to trigger rotation, confirm a new file is created.

Context

  • WG: Observability & DX
  • Priority: Low (disk hygiene)
  • Estimated effort: 1-2 hours

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/dxObservability & DX WGhelp wantedExtra attention is neededkind/bugCategorizes issue or PR as related to a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions