This is an automated email from the ASF dual-hosted git repository.

kaxilnaik pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new 0ec7b0fb66b Respect old logging format if given so logs don't change 
unexpectedly. (#55824)
0ec7b0fb66b is described below

commit 0ec7b0fb66b9408f14daedd91c88b17acc6fe653
Author: Ash Berlin-Taylor <[email protected]>
AuthorDate: Thu Sep 18 13:59:55 2025 +0100

    Respect old logging format if given so logs don't change unexpectedly. 
(#55824)
    
    If someone is upgrading from any earlier version, their config file with 
have
    `log_format` in it, even though we have now changed the default to an empty
    string.
    
    This also makes respects the colored_console_log config option
    
    If it is specified we should respect it, even though our new default has
    changed.
---
 airflow-core/src/airflow/logging_config.py                  | 13 +++++++++++--
 shared/logging/src/airflow_shared/logging/_config.py        |  9 +++++++--
 .../logging/src/airflow_shared/logging/percent_formatter.py |  3 ++-
 3 files changed, 20 insertions(+), 5 deletions(-)

diff --git a/airflow-core/src/airflow/logging_config.py 
b/airflow-core/src/airflow/logging_config.py
index 6d72dec53f4..0875ac9be90 100644
--- a/airflow-core/src/airflow/logging_config.py
+++ b/airflow-core/src/airflow/logging_config.py
@@ -89,11 +89,19 @@ def configure_logging():
 
     logging_config, logging_class_path = load_logging_config()
     try:
-        level: str = conf.get_mandatory_value("logging", 
"LOGGING_LEVEL").upper()
+        level: str = getattr(
+            logging_config, "LOG_LEVEL", conf.get("logging", "logging_level", 
fallback="INFO")
+        ).upper()
+
+        colors = getattr(
+            logging_config,
+            "COLORED_LOG",
+            conf.getboolean("logging", "colored_console_log", fallback=True),
+        )
         # Try to init logging
 
         log_fmt, callsite_params = translate_config_values(
-            log_format=conf.get("logging", "log_format"),
+            log_format=getattr(logging_config, "LOG_FORMAT", 
conf.get("logging", "log_format", fallback="")),
             callsite_params=conf.getlist("logging", "callsite_parameters", 
fallback=[]),
         )
         configure_logging(
@@ -101,6 +109,7 @@ def configure_logging():
             stdlib_config=logging_config,
             log_format=log_fmt,
             callsite_parameters=callsite_params,
+            colors=colors,
         )
     except (ValueError, KeyError) as e:
         log.error("Unable to load the config, contains a configuration error.")
diff --git a/shared/logging/src/airflow_shared/logging/_config.py 
b/shared/logging/src/airflow_shared/logging/_config.py
index 21d8aafa304..bd19b8dfdc4 100644
--- a/shared/logging/src/airflow_shared/logging/_config.py
+++ b/shared/logging/src/airflow_shared/logging/_config.py
@@ -20,6 +20,10 @@ from __future__ import annotations
 import structlog.processors
 
 OLD_DEFAULT_LOG_FORMAT = "[%(asctime)s] {%(filename)s:%(lineno)d} 
%(levelname)s - %(message)s"
+OLD_DEFAULT_COLOR_LOG_FORMAT = (
+    "[%(blue)s%(asctime)s%(reset)s] {%(blue)s%(filename)s:%(reset)s%(lineno)d} 
"
+    "%(log_color)s%(levelname)s%(reset)s - %(log_color)s%(message)s%(reset)s"
+)
 
 
 # This doesn't load the values from config, to avoid a cross dependency 
between shared logging and shared
@@ -28,8 +32,9 @@ def translate_config_values(
     log_format: str, callsite_params: list[str]
 ) -> tuple[str, tuple[structlog.processors.CallsiteParameter, ...]]:
     if log_format == OLD_DEFAULT_LOG_FORMAT:
-        # It's the default, don't use it, use the new default from structlog 
instead
-        log_format = ""
+        # It's the default, use the coloured version by default. This will 
automatically not put color codes
+        # if we're not a tty, or if colors are disabled
+        log_format = OLD_DEFAULT_COLOR_LOG_FORMAT
 
     # This will raise an exception if the value isn't valid
     params_out = tuple(
diff --git a/shared/logging/src/airflow_shared/logging/percent_formatter.py 
b/shared/logging/src/airflow_shared/logging/percent_formatter.py
index ec77f5ddbfc..33d566cf21e 100644
--- a/shared/logging/src/airflow_shared/logging/percent_formatter.py
+++ b/shared/logging/src/airflow_shared/logging/percent_formatter.py
@@ -140,7 +140,8 @@ class PercentFormatRender(ConsoleRenderer):
         params = _LazyLogRecordDict(
             event_dict,
             method_name,
-            ConsoleRenderer.get_default_level_styles(),
+            # To maintain compat with old log levels, we don't want to color 
info, just everything else
+            {**ConsoleRenderer.get_default_level_styles(), "info": ""},
             self._styles,
         )
 

Reply via email to