Skip to content

fix(server): only emit ANSI log colors when stdout is a TTY#108

Merged
thejefflarson merged 1 commit into
mainfrom
fix/log-ansi-tty
Jul 19, 2026
Merged

fix(server): only emit ANSI log colors when stdout is a TTY#108
thejefflarson merged 1 commit into
mainfrom
fix/log-ansi-tty

Conversation

@thejefflarson

Copy link
Copy Markdown
Owner

Problem

watcher's own process logs contain raw ANSI escape sequences (\x1b[2m…\x1b[0m) under Kubernetes. tracing_subscriber::fmt::layer() defaults with_ansi(true) regardless of whether the output is a terminal, so when stdout is piped (pod logs, kubectl logs, any redirect) the color codes leak into the log text as noise.

Fix

Gate ANSI on std::io::stdout().is_terminal() and additionally honor NO_COLOR (https://no-color.org):

tracing_subscriber::fmt::layer().with_ansi(
    std::io::stdout().is_terminal() && std::env::var_os("NO_COLOR").is_none(),
)
  • In-cluster / piped → no escape sequences, clean logs.
  • Local dev in a real terminal → colors preserved.
  • NO_COLOR=1 → force-disabled everywhere.

Testing

cargo fmt --check + cargo check clean. This is logging-init wiring with no unit-testable seam (the behavior is a TTY check on process stdout); verified the gate compiles and the IsTerminal import resolves. The runtime effect — no \x1b[ bytes in piped output — is the whole point and shows up the next time the rolled image writes to pod logs.

🤖 Generated with Claude Code

The tracing fmt layer defaults ANSI on regardless of output, so under
Kubernetes (piped, non-TTY stdout) the pod logs were littered with raw
`\x1b[..m` escape sequences. Gate coloring on `stdout().is_terminal()`
and honor `NO_COLOR` (https://no-color.org); a real terminal still gets
colors for local dev.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JbrmfzHsTMMzPaSrUkZgWo
@thejefflarson
thejefflarson merged commit c5cc7a5 into main Jul 19, 2026
4 checks passed
@thejefflarson
thejefflarson deleted the fix/log-ansi-tty branch July 19, 2026 02:39
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