From 628027585aaaa99f516e97a44a5cc3ad7baf6320 Mon Sep 17 00:00:00 2001 From: Daniel Standish <15932138+dstandish@users.noreply.github.com> Date: Tue, 3 Jan 2023 01:45:31 -0800 Subject: [PATCH] inline some code --- airflow/cli/commands/task_command.py | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/airflow/cli/commands/task_command.py b/airflow/cli/commands/task_command.py index 66566947317f7e..973b97540e2b67 100644 --- a/airflow/cli/commands/task_command.py +++ b/airflow/cli/commands/task_command.py @@ -298,26 +298,16 @@ def _move_task_handlers_to_root(ti: TaskInstance) -> Generator[None, None, None] yield return - def get_console_handler(logger): - for h in logger.handlers: - if h.name == "console": - return h - - def ensure_handler(logger, handler): - if not handler: - return - if handler not in logger.handlers: - logger.addHandler(handler) - # Move task handlers to root and reset task logger and restore original logger settings after exit. # If k8s executor, we need to ensure that root logger has a console handler, so that # task logs propagate to stdout (this is how webserver retrieves them while task is running). root_logger = logging.getLogger() - console_handler = get_console_handler(root_logger) + console_handler = next((h for h in root_logger.handlers if h.name == "console"), None) with LoggerMutationHelper(root_logger), LoggerMutationHelper(ti.log) as task_helper: task_helper.move(root_logger) if IS_K8S_EXECUTOR_POD: - ensure_handler(root_logger, console_handler) + if console_handler and console_handler not in root_logger.handlers: + root_logger.addHandler(console_handler) yield