#8617: fix: truncate large console payloads before writing to file log
stale
Cluster:
CLI Enhancements and Fixes
## Summary
- Add MAX_FILE_LOG_CHARS limit (2000 chars) for file log entries
- Truncate large console payloads before writing to file log
- Preserve full stdout output for user-facing commands
- Add truncation note to indicate content was trimmed
## Problem
Shell completion scripts (`openclaw completion --shell zsh`) output 3000+ lines. The console capture system mirrors all `console.log` output to file logs without any size limit, causing:
- Massive log entries (3500+ lines per invocation)
- Repeated bloating when `.zshrc` sources the completion on each shell start
- Noisy/unusable log files in `/tmp/openclaw/openclaw-*.log`
## Solution
Truncate messages to 2000 chars before writing to file log, while preserving full stdout output. The truncation adds a note like `[truncated 3000 chars for file log]` to indicate content was trimmed.
## Test plan
- [x] Ran `pnpm build && pnpm check && pnpm test` - all 207 tests pass
- [x] Added test verifying large payloads are truncated in file log but full output goes to stdout
## AI Disclosure
This PR was created with AI assistance (Claude Code). The changes are:
- **Testing level:** Fully tested - new test added, all tests pass
- **Understanding:** The fix adds a truncation function that limits file log entries to 2000 chars while preserving full console output to stdout/stderr
Fixes #8610
🤖 Generated with [Claude Code](https://claude.com/claude-code)
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
Adds a per-console-call size cap for file-backed logs by introducing `MAX_FILE_LOG_CHARS` and `truncateForFileLog()`, and updates `enableConsoleCapture()` to write truncated messages to the file logger while leaving stdout/stderr output unchanged. Also adds a Vitest covering that large console payloads are truncated in the file log while the full payload still reaches stdout via the original console function.
<h3>Confidence Score: 4/5</h3>
- This PR is likely safe to merge and should reduce log bloat with low behavioral risk.
- The change is localized to console capture file logging and is covered by a new test; main remaining concerns are edge cases around what exact string representation is truncated and potential test flakiness due to timing-based flush waits.
- src/logging/console.ts; src/logging/console-capture.test.ts
<!-- greptile_other_comments_section -->
<sub>(5/5) You can turn off certain types of comments like style [here](https://app.greptile.com/review/github)!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#12308: fix(cli): redirect log output to stderr during completion script ge...
by mcaxtr · 2026-02-09
79.9%
#16015: fix(gateway): truncate oversized message content in chat.history re...
by fagemx · 2026-02-14
77.7%
#11281: fix(logging): prevent subsystem loggers from bypassing file log lev...
by janckerchen · 2026-02-07
76.4%
#22488: fix(cli): redirect plugin logs to stderr during completion
by pierreeurope · 2026-02-21
75.1%
#11305: fix(logging): remove redundant subsystem prefix from log output
by janckerchen · 2026-02-07
74.9%
#23669: refactor(logging): migrate node-host and tailscale console calls to...
by kevinWangSheng · 2026-02-22
74.4%
#19826: fix: add in-prompt warnings and doctor check for bootstrap file tru...
by akramcodez · 2026-02-18
74.4%
#11549: lint: add no-console rule and migrate 5 files to structured logger
by vaibhavtupe · 2026-02-08
74.2%
#9148: Fix: Speed up shell completion generation from ~4.6s to <200ms
by vishaltandale00 · 2026-02-04
73.5%
#23803: Fix tool metadata truncation
by kamal-ayman · 2026-02-22
73.3%