Summary
Remove ANSI color codes from log files when using compact and pretty formats, or implement independent format control for file vs stderr outputs. Currently, both formats write ANSI escape sequences to log files, making them harder to parse with standard text tools (grep, awk, editors).
This is a follow-up refinement to #3, discovered during PR review.
Problem
When using --log-format compact or --log-format pretty with file logging, ANSI escape codes are written to files:
$ hexdump -C /tmp/logs/log.txt | head -5
00000000 1b 5b 32 6d 32 30 32 35 2d 31 30 2d 31 35 54 31 |.[2m2025-10-15T1|
00000010 35 3a 30 39 3a 33 31 2e 34 39 39 36 35 32 5a 1b |5:09:31.499652Z.|
00000020 5b 30 6d 20 1b 5b 33 32 6d 20 49 4e 46 4f 1b 5b |[0m .[32m INFO.[|
Why problematic:
- Hard to parse with grep/awk/sed
- 15-20% file size overhead
- Issues with plain text editors
- Log aggregation tools may not handle correctly
JSON format works correctly (no ANSI codes).
Recommended Solution
Option A: Independent format control (recommended)
- Add
--log-file-format and --log-stderr-format arguments
- Users choose exact format for each destination
- Automatically disable ANSI for file writers, enable for stderr
- Most flexible, no assumptions about user needs
Option B: Auto-detect destination (simpler but less flexible)
- Force no-ANSI when writing to files
- Keep same format for both outputs
Implementation
See full specification in docs/issues/remove-ansi-codes-from-file-logging.md
Key changes:
- Update CLI arguments in
src/app.rs
- Modify logging layer in
src/logging.rs to add .with_ansi(false) for files
- Update tests to verify ANSI presence/absence
- Update documentation
Estimated effort: 5-6 hours
Related
Summary
Remove ANSI color codes from log files when using
compactandprettyformats, or implement independent format control for file vs stderr outputs. Currently, both formats write ANSI escape sequences to log files, making them harder to parse with standard text tools (grep, awk, editors).This is a follow-up refinement to #3, discovered during PR review.
Problem
When using
--log-format compactor--log-format prettywith file logging, ANSI escape codes are written to files:Why problematic:
JSON format works correctly (no ANSI codes).
Recommended Solution
Option A: Independent format control (recommended)
--log-file-formatand--log-stderr-formatargumentsOption B: Auto-detect destination (simpler but less flexible)
Implementation
See full specification in
docs/issues/remove-ansi-codes-from-file-logging.mdKey changes:
src/app.rssrc/logging.rsto add.with_ansi(false)for filesEstimated effort: 5-6 hours
Related
docs/issues/remove-ansi-codes-from-file-logging.md