Skip to content

Commit

Permalink
TaskLogReader should check both "airflow.task" and root logger for ha…
Browse files Browse the repository at this point in the history
…ndler. (apache#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.
  • Loading branch information
dstandish authored Apr 25, 2023
1 parent 3af22f5 commit 4a1d5b2
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions airflow/utils/log/log_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,19 @@ def read_log_stream(self, ti: TaskInstance, try_number: int | None, metadata: di

@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):
Expand Down

0 comments on commit 4a1d5b2

Please sign in to comment.