Repository navigation
Description
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-formatand--log-stderr-formatarguments - 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.rsto add.with_ansi(false)for files - Update tests to verify ANSI presence/absence
- Update documentation
Estimated effort: 5-6 hours
Related
- Parent: Scaffolding for main app - 8/9 tasks complete (89%) #2 (Scaffolding for main app)
- Related: Setup logging for production CLI #3 (Setup logging for production CLI)
- Documentation:
docs/issues/remove-ansi-codes-from-file-logging.md
Activity
docs: add follow-up issue #5 for ANSI codes in file logging
Merge #4: feat: [#3] Setup logging for production CLI with configurab…
Merge #7: feat: add independent format control for file and stderr lo…
chore: remove completed issue documentation files
refactor: [#61] standardize logging patterns (Proposal #5)
Merge #62: refactor: command handlers refactoring (Issue #61)
docs: [#17] add comprehensive guide for adding static Ansible playbooks
fix: [#174] correct repository factory path in provision controller
fix: [#174] fix E2E test repository path (Bug #7)
refactor: [#281] HttpsConfig validated constructor (Proposal #5)
Merge #282: refactor: [#281] strengthen domain invariant enforcement