This is an automated email from the ASF dual-hosted git repository. ephraimanierobi pushed a commit to branch v2-6-test in repository https://gitbox.apache.org/repos/asf/airflow.git
commit 416d66d15e7d63e3c462d68e4784d6802dc6fd39 Author: Daniel Standish <[email protected]> AuthorDate: Tue Apr 25 12:43:59 2023 -0700 TaskLogReader should check both "airflow.task" and root logger for handler. (#30860) When task is running, handlers are moved from airflow.task to root. Under normal circumstances this is a non-issue because the reader is instantiated in a webserver but there are certain contrived scenarios such as test dags which instantiate the reader in the context of a running task. (cherry picked from commit 4a1d5b2c2b77ee346e6052bf76dfc5514dccd98b) --- airflow/utils/log/log_reader.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/airflow/utils/log/log_reader.py b/airflow/utils/log/log_reader.py index 5cc8b9377e..63529e71e2 100644 --- a/airflow/utils/log/log_reader.py +++ b/airflow/utils/log/log_reader.py @@ -97,11 +97,19 @@ class TaskLogReader: @cached_property def log_handler(self): - """Log handler, which is configured to read logs.""" - logger = logging.getLogger("airflow.task") + """Get the log handler which is configured to read logs.""" task_log_reader = conf.get("logging", "task_log_reader") - handler = next((handler for handler in logger.handlers if handler.name == task_log_reader), None) - return handler + + def handlers(): + """ + Yield all handlers first from airflow.task logger then root logger. + + Depending on whether we're in a running task, it could be in either of these locations. + """ + yield from logging.getLogger("airflow.task").handlers + yield from logging.getLogger().handlers + + return next((h for h in handlers() if h.name == task_log_reader), None) @property def supports_read(self):
