Skip to content

Commit

Permalink
inline some code
Browse files Browse the repository at this point in the history
  • Loading branch information
dstandish committed Jan 4, 2023
1 parent 6b8b153 commit 6280275
Showing 1 changed file with 3 additions and 13 deletions.
16 changes: 3 additions & 13 deletions airflow/cli/commands/task_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down

0 comments on commit 6280275

Please sign in to comment.