<#10118 fix(cli): Disable colors when stderr is no...
# meltano-repo-activity
g
#10118 fix(cli): Disable colors when stderr is not a TTY Pull request opened by gbadedata Summary Closes #6152. This updates Meltano’s generated default logging configuration so colored log output is disabled when
sys.stderr
is not attached to a TTY. The change is intentionally narrow: • Default colored logging now respects non-TTY stderr streams. •
NO_COLOR
behavior is preserved. • Custom
logging.yaml
behavior is not changed. • Existing CLI color behavior is not refactored. Details Previously, the default
LogFormat.colored
path only checked
NO_COLOR
before enabling
MeltanoConsoleRenderer(colors=True)
. This meant ANSI color codes could still appear in redirected or piped stderr output. This change updates the default config path to disable logging colors when: get_no_color_flag() or not sys.stderr.isatty() I kept the change inside
default_config()
rather than
console_log_formatter()
so custom logging configurations that explicitly set
colors=True
continue to behave as configured. Investigation I also checked the Click usage across the CLI. There are many
click.echo
,
click.secho
, and
click.style
calls, and the existing color tests already exercise Click output separately through
CliRunner(color=True)
. I did not change Click output behavior in this PR because the reported issue is specifically about log output written to stderr. I also checked the structlog/Rich logging path. Meltano’s generated default logging config explicitly passes
colors=not no_color
into
MeltanoConsoleRenderer
, so the default path was bypassing any automatic TTY-based color decision. This PR adds the TTY check at that point. Tests uv run pytest tests/meltano/cli/test_cli.py:TestCliColors:test_no_color uv run pytest tests/meltano/cli/test_cli.py::TestCliColors uv run --with ruff ruff check src/meltano/core/logging/utils.py tests/meltano/cli/test_cli.py uv run --with ruff ruff format --check src/meltano/core/logging/utils.py tests/meltano/cli/test_cli.py GIT_PAGER=cat git diff --check Results: •
10 passed
for
TestCliColors::test_no_color
•
10 passed
for
TestCliColors
• Ruff checks passed • Ruff format check passed •
git diff --check
passed Summary by Sourcery Disable colored log output in the default logging configuration when stderr is not a TTY. Bug Fixes: • Prevent ANSI color codes from appearing in log output when stderr is redirected or not attached to a TTY. Tests: • Extend CLI color tests to cover non-TTY stderr behavior and ensure custom logging configurations can still explicitly enable colors. meltano/meltano