Skip to content

fix(cli): add log rotation for fern docs dev debug logs#14758

Merged
thesandlord merged 9 commits into
mainfrom
devin/fer-9568-1775674587
Apr 8, 2026
Merged

fix(cli): add log rotation for fern docs dev debug logs#14758
thesandlord merged 9 commits into
mainfrom
devin/fer-9568-1775674587

Conversation

@thesandlord
Copy link
Copy Markdown
Contributor

@thesandlord thesandlord commented Apr 8, 2026

Description

Closes FER-9568

fern docs dev writes debug logs to ~/.fern/logs/ but never cleans them up, causing unbounded disk usage over time. This adds automatic log rotation with a 100 MB directory size cap.

Changes Made

  • Added enforceLogSizeLimit() private method in DebugLogger that runs fire-and-forget at the end of initialize()
  • Scans the logs directory, sorts files by mtime (oldest first), and deletes until total size is ≤ 100 MB
  • Skips the current session's log file to avoid deleting active logs
  • Added optional consoleLogger callback parameter to DebugLogger.initialize() so rotation status is logged to the console (debug when under cap, info when rotating) — wired to context.logger in runAppPreviewServer.ts
  • All errors are silently caught to avoid breaking the main fern docs dev flow
  • Added versions.yml entry (4.63.2, fix)

Review Checklist

  • file.fullPath === this.logFilePath comparison: this.logFilePath is an AbsoluteFilePath (branded string), while file.fullPath is built with path.join() (plain string). Works at runtime since AbsoluteFilePath is string & { __AbsoluteFilePath: void }, but verify paths are normalized consistently.
  • Cleanup runs fire-and-forget (void) — does not block startup
  • Cleanup only runs at startup — a single very long session could still exceed 100 MB. Acceptable tradeoff.

Testing

  • Unit tests added/updated — not added; cleanup logic is defensive (all errors caught) and straightforward
  • Lint passes (biome check)
  • Verified console output shows rotation status with --log-level=debug

Link to Devin session: https://app.devin.ai/sessions/0212b2e6da7543248d179fb0d4f0450a
Requested by: @thesandlord

@devin-ai-integration
Copy link
Copy Markdown
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

Copy link
Copy Markdown

@claude claude Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review to trigger a review and subscribe this PR to future pushes, or @claude review once for a one-time review.

Tip: disable this comment in your organization's Code Review settings.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 8, 2026

🌱 Seed Test Selector

Select languages to run seed tests for:

  • Python
  • TypeScript
  • Java
  • Go
  • Ruby
  • C#
  • PHP
  • Swift
  • Rust
  • OpenAPI

How to use: Click the ⋯ menu above → "Edit" → check the boxes you want → click "Update comment". Tests will run automatically and snapshots will be committed to this PR.

this.initialized = true;

// Enforce the 100 MB cap on the logs directory
await this.enforceLogSizeLimit(logsDir);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dont await, run in bg

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call — changed to void this.enforceLogSizeLimit(logsDir) so it runs fire-and-forget without blocking startup.

* Delete oldest log files until total directory size is within the cap.
*/
private async enforceLogSizeLimit(logsDir: AbsoluteFilePath): Promise<void> {
try {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a debug log here "rotating logs" or something like that

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a log_rotation debug entry that logs total size, file count, and the cap before deletion starts.

Comment thread packages/cli/docs-preview/src/DebugLogger.ts
devin-ai-integration Bot and others added 4 commits April 8, 2026 19:31
Enforce a 100 MB cap on ~/.fern/logs/. On each fern docs dev startup,
the DebugLogger now scans the logs directory and deletes the oldest
.log files until total size is within the limit.

Closes FER-9568

Co-Authored-By: Sandeep Dinesh <sandeep@buildwithfern.com>
Co-Authored-By: Sandeep Dinesh <sandeep@buildwithfern.com>
Co-Authored-By: Sandeep Dinesh <sandeep@buildwithfern.com>
Co-Authored-By: Sandeep Dinesh <sandeep@buildwithfern.com>
@devin-ai-integration devin-ai-integration Bot force-pushed the devin/fer-9568-1775674587 branch from 8e6aafe to 71be4a0 Compare April 8, 2026 19:32
devin-ai-integration Bot and others added 5 commits April 8, 2026 19:38
Co-Authored-By: Sandeep Dinesh <sandeep@buildwithfern.com>
…rver

Co-Authored-By: Sandeep Dinesh <sandeep@buildwithfern.com>
Co-Authored-By: Sandeep Dinesh <sandeep@buildwithfern.com>
Co-Authored-By: Sandeep Dinesh <sandeep@buildwithfern.com>
…allback

Co-Authored-By: Sandeep Dinesh <sandeep@buildwithfern.com>
@thesandlord thesandlord enabled auto-merge (squash) April 8, 2026 20:05
@thesandlord thesandlord disabled auto-merge April 8, 2026 20:05
@thesandlord thesandlord merged commit 3411a96 into main Apr 8, 2026
59 checks passed
@thesandlord thesandlord deleted the devin/fer-9568-1775674587 branch April 8, 2026 20:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants