This is an automated email from the ASF dual-hosted git repository.
dstandish 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 4a1d5b2c2b TaskLogReader should check both "airflow.task" and root
logger for handler. (#30860)
4a1d5b2c2b is described below
commit 4a1d5b2c2b77ee346e6052bf76dfc5514dccd98b
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.
---
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):