Skip to content

Use TaskFormatter for Celery log formatting instead of default Formatter - #61701

Merged
shahar1 merged 4 commits into
apache:mainfrom
aaron-y-chen:bug-49966-error_in_celery_worker_logs
Feb 10, 2026
Merged

shahar1 merged 4 commits into
apache:mainfrom
aaron-y-chen:bug-49966-error_in_celery_worker_logs

Conversation

@aaron-y-chen

Copy link
Copy Markdown
Contributor

related: #49966

Why

When setting AIRFLOW__LOGGING__CELERY_STDOUT_STDERR_SEPARATION=True, it will use DEFAULT_TASK_LOG_FMT as the log format.

if conf.getboolean("logging", "celery_stdout_stderr_separation", fallback=False):
celery_formatter = logging.Formatter(DEFAULT_TASK_LOG_FMT)


However, DEFAULT_TASK_LOG_FMT contains task_name and task_id which are not handled by the default logging.Formatter.

>>> from celery.app.defaults import DEFAULT_TASK_LOG_FMT
>>> print(DEFAULT_TASK_LOG_FMT)
[%(asctime)s: %(levelname)s/%(processName)s] %(task_name)s[%(task_id)s]: %(message)s

How

Use TaskFormatter from Celery to handle task_name and task_id.

Ref: https://github.com/celery/celery/blob/main/celery/app/log.py#L41-L42

What

Set AIRFLOW__LOGGING__CELERY_STDOUT_STDERR_SEPARATION=True.
Then start Airflow with: breeze start-airflow --executor CeleryExecutor --integration celery.

  • Before fix
49966_before_fixed
  • After fix
49966_after_fixed
Was generative AI tooling used to co-author this PR?
  • No (please specify the tool below)

  • Read the Pull Request Guidelines for more information. Note: commit author/co-author name and email in commits become permanently public when merged.
  • For fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
  • When adding dependency, check compliance with the ASF 3rd Party License Policy.
  • For significant user-facing changes create newsfragment: {pr_number}.significant.rst or {issue_number}.significant.rst, in airflow-core/newsfragments.

@shahar1 shahar1 left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll reckon that logs with arbitrary question marks are better than a blocking error.
I'd rather include it in the upcoming release, and we could handle the question marks later.

@eladkal @amoghrajesh - WDYT?

@shahar1 shahar1 changed the title Use TaskFormatter for Celery log formatting instead of default Formatter (#49966) Use TaskFormatter for Celery log formatting instead of default Formatter Feb 10, 2026
@shahar1
shahar1 merged commit 602c997 into apache:main Feb 10, 2026
85 checks passed
Ratasa143 pushed a commit to Ratasa143/airflow that referenced this pull request Feb 15, 2026
dominikhei pushed a commit to dominikhei/airflow that referenced this pull request Mar 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants