aga98 opened a new issue, #56421:
URL: https://github.com/apache/airflow/issues/56421

   ### Apache Airflow version
   
   3.1.0
   
   ### If "Other Airflow 2 version" selected, which one?
   
   _No response_
   
   ### What happened?
   
   In Airflow 3.0.0+, task logs displayed in the Airflow UI no longer render 
colored or styled messages.
   
   In Airflow 2.x, if a task log message contained ANSI escape codes (e.g., 
from using the Python logging or logs generated by dbt), the Airflow UI 
(specifically the Task Log view) would render these colors, significantly 
improving the readability and triage speed for log analysis.
   
   With the switch to structured logging (JSON format) in Airflow 3+, the logs 
are now rendered from the structured data, and any color/style information 
present in the original log message is logged as raw.
   
   Check this example in Airflow 3.1.0:
   
   <img width="1419" height="239" alt="Image" 
src="https://github.com/user-attachments/assets/101cf003-d912-4680-9982-440192c73125";
 />
   
   The color codes `[34m` and `[0m` are displayed and ignored for the 
formatting of the log.
   
   This also affects formatted logs coming from dbt executions. For example:
   
   <img width="1089" height="111" alt="Image" 
src="https://github.com/user-attachments/assets/d9a3aa43-d5e5-4352-a335-b60ec3108f4b";
 />
   
   
   ### What you think should happen instead?
   
   The Airflow UI should re-introduce the functionality to display 
styled/colored log messages in the Task Log view.
   
   Since the logs are now structured, the ideal solution would be to re-enable 
ANSI Code Interpretation: If the log message (event field in the JSON log) 
contains ANSI escape codes, the UI should be able to interpret and apply these 
styles to the rendered message, as it did in Airflow 2.
   
   Check the same example in Airflow 2.9.3
   
   <img width="1327" height="244" alt="Image" 
src="https://github.com/user-attachments/assets/dea3f854-6fe8-4c45-84cf-998d7ad1f5d8";
 />
   
   And for dbt:
   
   <img width="1061" height="92" alt="Image" 
src="https://github.com/user-attachments/assets/67dfb374-6638-4e0c-973c-0de8a8b26871";
 />
   
   ### How to reproduce
   
   The following DAG can be added to Airflow to validate how the color codes 
are not rendered correctly:
   
   ```python
   import logging
   from datetime import datetime
   
   from airflow.sdk import dag, task
   # for Airflow 2
   # from airflow.decorators import dag, task
   
   log = logging.getLogger(__name__)
   
   @dag(
       dag_id="color_log_reproduction_dag",
       start_date=datetime(2025, 1, 1),
       schedule=None,
       catchup=False,
   )
   def check_log_colors():
       """DAG to test rendering of ANSI-colored logs in the Airflow 3 UI."""
   
       @task
       def log_colored_messages():
           # ANSI Codes: \033[91m = Red, \033[93m = Yellow, \033[0m = Reset
           log.error("\033[91mThis ERROR message should be RED in the 
UI.\033[0m")
           log.warning("\033[93mThis WARNING message should be YELLOW in the 
UI.\033[0m")
           log.info( "This line contains \033[91mRED\033[0m text mid-message.")
   
       log_colored_messages()
   
   check_log_colors()
   ```
   
   Output for Airflow 3:
   
   <img width="1271" height="138" alt="Image" 
src="https://github.com/user-attachments/assets/f8c895f9-95ce-4f16-a88a-448558dc0d75";
 />
   
   Output for Airflow 2:
   
   <img width="724" height="98" alt="Image" 
src="https://github.com/user-attachments/assets/8a62283e-7b50-44ae-9738-0a6145804cf2";
 />
   
   ### Operating System
   
   Debian GNU/Linux 12 (bookworm)
   
   ### Versions of Apache Airflow Providers
   
   _No response_
   
   ### Deployment
   
   Official Apache Airflow Helm Chart
   
   ### Deployment details
   
   _No response_
   
   ### Anything else?
   
   _No response_
   
   ### Are you willing to submit PR?
   
   - [ ] Yes I am willing to submit a PR!
   
   ### Code of Conduct
   
   - [x] I agree to follow this project's [Code of 
Conduct](https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md)
   


-- 
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]

Reply via email to