Skip to content

Commit 416d66d

Browse files
dstandishephraimbuddy
authored andcommitted
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 4a1d5b2)
1 parent 969381d commit 416d66d

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

airflow/utils/log/log_reader.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,19 @@ def read_log_stream(self, ti: TaskInstance, try_number: int | None, metadata: di
9797

9898
@cached_property
9999
def log_handler(self):
100-
"""Log handler, which is configured to read logs."""
101-
logger = logging.getLogger("airflow.task")
100+
"""Get the log handler which is configured to read logs."""
102101
task_log_reader = conf.get("logging", "task_log_reader")
103-
handler = next((handler for handler in logger.handlers if handler.name == task_log_reader), None)
104-
return handler
102+
103+
def handlers():
104+
"""
105+
Yield all handlers first from airflow.task logger then root logger.
106+
107+
Depending on whether we're in a running task, it could be in either of these locations.
108+
"""
109+
yield from logging.getLogger("airflow.task").handlers
110+
yield from logging.getLogger().handlers
111+
112+
return next((h for h in handlers() if h.name == task_log_reader), None)
105113

106114
@property
107115
def supports_read(self):

0 commit comments

Comments
 (0)