Skip to content

feat: rotate debug logs at 128 MB or 30 days - #15

Merged
jatmn merged 8 commits into
mainfrom
feat/debug-log-rotation
Aug 6, 2026
Merged

feat: rotate debug logs at 128 MB or 30 days#15
jatmn merged 8 commits into
mainfrom
feat/debug-log-rotation

Conversation

@jatmn

@jatmn jatmn commented Aug 5, 2026

Copy link
Copy Markdown
Owner

Summary

  • Rotate the active debug JSONL log when it reaches 128 MB or the current log file is older than 30 days, whichever comes first.
  • Keeps one backup as {log_path}.1 and starts a fresh log file.
  • Optional TOML overrides: debug.max_log_mb and debug.max_log_age_days.
  • Age is measured from the log file's creation time when the platform provides it (start of the current log segment), otherwise from last modification time.

Test plan

  • cargo test
  • Unit tests for rotation thresholds, staging rename, directory rejection, and creation-time age semantics

@jatmn jatmn self-assigned this Aug 5, 2026
@jatmn jatmn added the enhancement New feature or request label Aug 5, 2026
jatmn added 5 commits August 5, 2026 20:25
Prevent unbounded JSONL growth by rotating the active debug log before
startup and each write when size or age limits are exceeded.
Express debug log size limits in megabytes (default 128) for simpler TOML.
- Use OsString manipulation for the backup path so non-UTF-8 paths round-trip.
- Document max_log_mb, max_log_age_days, and per-instance log_path guidance.
- Add age-based rotation integration test.
- Treat max_log_mb = 0 and max_log_age_days = 0 as invalid (fallback to defaults).
- Fix clippy collapsible_if warning in DebugLog::new.
- Clean up temp directories on test panic via TempDirGuard.

Signed-off-by: jatmn <the@jat.mn>
Use file creation time for age limits when available, rotate through a
staging file so backup removal failures do not drop the active log,
reject directory log paths, and document age semantics in configuration.
@jatmn
jatmn force-pushed the feat/debug-log-rotation branch from 669907d to d4cc951 Compare August 6, 2026 03:25
jatmn added 3 commits August 5, 2026 20:47
…emantics

Restore or promote orphaned `.rotating` staging files after a crash so
segments are not discarded on the next rotation, and clarify that
mtime-only filesystems only age-rotate idle logs.
Promote staged segments through a pending backup path and only retire the
previous {log_path}.1 after the new backup rename succeeds, so a failed
promotion restores both the active segment and the prior backup.
Finish or roll back orphaned {log_path}.1.new and {log_path}.1.old
states after a crash between promotion renames instead of deleting
them on the next rotation. Add regression tests for pending-only and
pending-plus-retired recovery paths.

Validated with cargo fmt --check, cargo test --locked.
@jatmn
jatmn merged commit 8fc9d93 into main Aug 6, 2026
3 checks passed
@jatmn
jatmn deleted the feat/debug-log-rotation branch August 6, 2026 05:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant