Skip to content

Send Airflow CLI logs to stderr for -o commands so structured output stays parseable#68598

Open
dheerajturaga wants to merge 1 commit into
apache:mainfrom
dheerajturaga:cli-logs-to-stderr-for-structured-output
Open

Send Airflow CLI logs to stderr for -o commands so structured output stays parseable#68598
dheerajturaga wants to merge 1 commit into
apache:mainfrom
dheerajturaga:cli-logs-to-stderr-for-structured-output

Conversation

@dheerajturaga

@dheerajturaga dheerajturaga commented Jun 15, 2026

Copy link
Copy Markdown
Member

CLI commands that accept -o (table|json|yaml|plain) write structured data to stdout. Airflow's default logging config routes the root console handler to sys.stdout, so any log line emitted while such a command runs is mixed into that data and breaks downstream parsers (most visibly: the Celery default visibility_timeout warning corrupts airflow celery list-workers -o json output).

After parse_args() in the CLI entrypoint, redirect any root-logger StreamHandler whose stream is sys.stdout to sys.stderr, gated on hasattr(args, 'output'). Daemon commands (scheduler, api-server, celery worker, ...) do not register -o and so keep their existing stdout-logging behavior.

image
Was generative AI tooling used to co-author this PR?
  • Yes (please specify the tool below)
    Claude Code Opus 4.7

…stays parseable

CLI commands that accept -o (table|json|yaml|plain) write structured data
to stdout. Airflow's default logging config routes the root console handler
to sys.stdout, so any log line emitted while such a command runs is mixed
into that data and breaks downstream parsers (most visibly: the Celery
default visibility_timeout warning corrupts `airflow celery list-workers
-o json` output).

After parse_args() in the CLI entrypoint, redirect any root-logger
StreamHandler whose stream is sys.stdout to sys.stderr, gated on
hasattr(args, 'output'). Daemon commands (scheduler, api-server,
celery worker, ...) do not register -o and so keep their existing
stdout-logging behavior.
@dheerajturaga dheerajturaga force-pushed the cli-logs-to-stderr-for-structured-output branch from 84dc03b to 89f3c62 Compare June 25, 2026 02:26
@vatsrahul1001

Copy link
Copy Markdown
Contributor

Moving to 3.3.1 as planning to only include critical/high priority bug fixes to 3.3.0 found in 3.3.0b2 testing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants