Skip to content

Conversation

@highlyavailable
Copy link
Contributor

Fixes #50963

This PR separates the control of log format (console vs JSON) from log styling (colors and rich traces) in the Task SDK logging configuration. Previously, the single enable_pretty_log boolean controlled both aspects, making it impossible to have console logs without colors and rich traces.

Problem

  • Single enable_pretty_log boolean controlled BOTH format (console vs JSON) AND styling (colors + rich traces)
  • No way to get console logger without colors and rich traces
  • Celery workers showed color escape sequences as raw text in log ingestion solutions like Splunk

Solution

  • Separated enable_pretty_log (format) from enable_colors (styling)
  • enable_pretty_log=True + enable_colors=False = plain text console logger (no colors, no rich traces)
  • Respects existing colored_console_log configuration parameter
  • Celery workers automatically respect the configuration without code changes
  • Change is backwards compatible since:
    • configure_logging() - uses default enable_colors=None → reads config
    • logging_processors(enable_pretty_log=True) - uses default enable_colors=True

New Behavior Matrix:

enable_pretty_log enable_colors Result
True True Colorized console + rich traces + "%Y-%m-%d %H:%M:%S.%f" timestamps
True False Plain text console + no rich traces + "%Y-%m-%d %H:%M:%S.%f" timestamps
False True/False JSON logger + ISO timestamps + dict exception renderer

Testing

All new & existing tests are passing, as well as the pre-commit checks. I wrote some simple unit tests in the test SDK,

  • test_logging_processors_with_colors(): Verifies colored console renderer
  • test_logging_processors_without_colors(): Verifies non-colored console renderer
  • test_logging_processors_json_format(): Verifies JSON renderer unchanged
  • test_configure_logging_respects_colored_console_log_config(): Tests configuration reading
  • test_configure_logging_explicit_enable_colors(): Tests explicit parameter override
  • test_configure_logging_no_airflow_config(): Tests fallback behavior

Since I am new to the project, I also wrote a short testing script (attached as a .txt) and ran it in my local Breeze environment, here were the results:

demo_test.txt

image

…'logging_processors' and 'configure_logging' functions. This allows for customizable console output with or without colors based on user preference or configuration settings.
@amoghrajesh amoghrajesh changed the title Fix/50963 Separate configurations for colorized and json logs in Task SDK / Celery Executor Separate configurations for colorized and json logs in Task SDK / Celery Executor May 27, 2025
@amoghrajesh
Copy link
Contributor

@highlyavailable would you be able to address review comments so we can target this for Airflow 3.0.2 whose RC cut is on Tuesday?

@highlyavailable
Copy link
Contributor Author

Yes I will get it done this morning

- Remove conditional imports, use direct \
- Rename parameter from \ to \ to match existing config
- Remove unrelated formatting options (show_locals) from color logic
- Update tests to reflect the changes
@highlyavailable
Copy link
Contributor Author

@highlyavailable would you be able to address review comments so we can target this for Airflow 3.0.2 whose RC cut is on Tuesday?

@amoghrajesh I believe my most recent commit addresses all of the feedback in this thread.

@amoghrajesh
Copy link
Contributor

@uranusjr does the PR address your review comments?

Copy link
Contributor

@amoghrajesh amoghrajesh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One comment, more like a nit, can be addressed now or in a followup.

@amoghrajesh amoghrajesh added the backport-to-v3-1-test Mark PR with this label to backport to v3-1-test branch label Jun 3, 2025
@amoghrajesh amoghrajesh added this to the Airflow 3.0.2 milestone Jun 3, 2025
@amoghrajesh amoghrajesh merged commit e25351d into apache:main Jun 3, 2025
71 checks passed
@boring-cyborg
Copy link

boring-cyborg bot commented Jun 3, 2025

Awesome work, congrats on your first merged pull request! You are invited to check our Issue Tracker for additional contributions.

github-actions bot pushed a commit that referenced this pull request Jun 3, 2025
…sk SDK / Celery Executor (#51082)

* Enhance logging configuration by adding 'enable_colors' parameter to 'logging_processors' and 'configure_logging' functions. This allows for customizable console output with or without colors based on user preference or configuration settings.
(cherry picked from commit e25351d)

Co-authored-by: Peter Bryant <pwbryant1@gmail.com>
@github-actions
Copy link

github-actions bot commented Jun 3, 2025

Backport successfully created: v3-0-test

Status Branch Result
v3-0-test PR Link

github-actions bot pushed a commit to aws-mwaa/upstream-to-airflow that referenced this pull request Jun 3, 2025
…sk SDK / Celery Executor (apache#51082)

* Enhance logging configuration by adding 'enable_colors' parameter to 'logging_processors' and 'configure_logging' functions. This allows for customizable console output with or without colors based on user preference or configuration settings.
(cherry picked from commit e25351d)

Co-authored-by: Peter Bryant <pwbryant1@gmail.com>
kaxil pushed a commit that referenced this pull request Jun 3, 2025
…sk SDK / Celery Executor (#51082) (#51344)

* Enhance logging configuration by adding 'enable_colors' parameter to 'logging_processors' and 'configure_logging' functions. This allows for customizable console output with or without colors based on user preference or configuration settings.
(cherry picked from commit e25351d)

Co-authored-by: Peter Bryant <pwbryant1@gmail.com>
kaxil pushed a commit that referenced this pull request Jun 3, 2025
…sk SDK / Celery Executor (#51082) (#51344)

* Enhance logging configuration by adding 'enable_colors' parameter to 'logging_processors' and 'configure_logging' functions. This allows for customizable console output with or without colors based on user preference or configuration settings.
(cherry picked from commit e25351d)

Co-authored-by: Peter Bryant <pwbryant1@gmail.com>
sanederchik pushed a commit to sanederchik/airflow that referenced this pull request Jun 7, 2025
…ery Executor (apache#51082)

* Enhance logging configuration by adding 'enable_colors' parameter to 'logging_processors' and 'configure_logging' functions. This allows for customizable console output with or without colors based on user preference or configuration settings.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:task-sdk backport-to-v3-1-test Mark PR with this label to backport to v3-1-test branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Separate configurations for colorised and json logs in Task SDK / Celery Executor

5 participants