highlyavailable opened a new pull request, #51082:
URL: https://github.com/apache/airflow/pull/51082
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](https://github.com/user-attachments/files/20443592/demo_test.txt)
<img width="751" alt="image"
src="https://github.com/user-attachments/assets/4618c04f-04f9-4bbd-8dd1-8f4d3c647634"
/>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]