Skip to content

fix: wire config logLevel and add 50MB log file rotation (#558)#642

Open
MrRealORG wants to merge 1 commit into
XiaomiMiMo:mainfrom
MrRealORG:fix/auto-202606150437-log-rotation-level
Open

fix: wire config logLevel and add 50MB log file rotation (#558)#642
MrRealORG wants to merge 1 commit into
XiaomiMiMo:mainfrom
MrRealORG:fix/auto-202606150437-log-rotation-level

Conversation

@MrRealORG

Copy link
Copy Markdown

Summary

Addresses #558 (log files growing to 50GB+ in hours) with two fixes:

1. Config `logLevel` was never applied (bug)

The `logLevel` field was defined in the config schema (`config.ts:99`) and documented for users, but never read at runtime. `Log.init()` in `index.ts` only checked the CLI `--log-level` flag and `Installation.isLocal()`. Users who set `"logLevel": "WARN"` in their config file saw no effect.

Fix: Added `Log.setLevel()` export and called it in `InstanceBootstrap` right after config is loaded. CLI `--log-level` still takes precedence (applied first in middleware), but config file now works as a fallback.

2. No per-file size cap (feature)

Log files grew unbounded via `createWriteStream(path, { flags: "a" })`. A single session could produce tens of GB.

Fix: Added 50MB max file size with automatic rotation:

  • Tracks `currentSize` as bytes are written
  • When `currentSize + len > MAX_LOG_SIZE`, triggers rotation
  • Rotation: closes stream, shifts `.log → .log.1 → .log.2 → ... → .log.9`, truncates original, opens fresh stream
  • A `rotating` guard prevents concurrent rotations
  • Existing timestamped-file cleanup (keeps 10) continues alongside rotation

Test Plan

  • Set `"logLevel": "WARN"` in mimocode.json, verify debug/info messages are suppressed
  • Set `"logLevel": "ERROR"`, verify only errors appear
  • Verify CLI `--log-level DEBUG` still overrides config
  • Run a long session, verify log file rotates at ~50MB
  • Verify rotated files (.log.1, .log.2, ...) exist and are valid
  • Verify no log messages are lost during rotation

)

Two fixes for excessive log disk usage:

1. Config logLevel was a dead field — defined in the config schema
   but never read at runtime. Log.init() only checked the CLI
   --log-level flag and Installation.isLocal(). Now InstanceBootstrap
   applies cfg.logLevel from the config file after loading it.

2. No per-file size cap — log files grew unbounded via append-only
   write stream. Added 50MB max size per file with automatic rotation:
   when a file exceeds the limit it is rotated (.log.1, .log.2, ...
   .log.9) and a fresh file is started. Existing file-count cleanup
   (keeps 10 timestamped logs) continues to work alongside rotation.
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