Skip to content

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

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

Use TaskFormatter for Celery log formatting instead of default Formatter#61701
shahar1 merged 4 commits into
apache:mainfrom
nailo2c:bug-49966-error_in_celery_worker_logs

Conversation

@nailo2c

@nailo2c nailo2c commented Feb 10, 2026

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?

Comment thread providers/celery/src/airflow/providers/celery/cli/celery_command.py
@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
86 checks passed
Alok-kumar-priyadarshi pushed a commit to Alok-kumar-priyadarshi/airflow that referenced this pull request Feb 11, 2026
…ter (apache#61701)

Co-authored-by: Shahar Epstein <60007259+shahar1@users.noreply.github.com>
Ratasa143 pushed a commit to Ratasa143/airflow that referenced this pull request Feb 15, 2026
…ter (apache#61701)

Co-authored-by: Shahar Epstein <60007259+shahar1@users.noreply.github.com>
choo121600 pushed a commit to choo121600/airflow that referenced this pull request Feb 22, 2026
…ter (apache#61701)

Co-authored-by: Shahar Epstein <60007259+shahar1@users.noreply.github.com>
AkshayArali pushed a commit to AkshayArali/airflow_630 that referenced this pull request Feb 27, 2026
…ter (apache#61701)

Co-authored-by: Shahar Epstein <60007259+shahar1@users.noreply.github.com>
AkshayArali pushed a commit to AkshayArali/airflow_630 that referenced this pull request Feb 27, 2026
…ter (apache#61701)

Co-authored-by: Shahar Epstein <60007259+shahar1@users.noreply.github.com>
Subham-KRLX pushed a commit to Subham-KRLX/airflow that referenced this pull request Mar 4, 2026
…ter (apache#61701)

Co-authored-by: Shahar Epstein <60007259+shahar1@users.noreply.github.com>
dominikhei pushed a commit to dominikhei/airflow that referenced this pull request Mar 11, 2026
…ter (apache#61701)

Co-authored-by: Shahar Epstein <60007259+shahar1@users.noreply.github.com>
Ankurdeewan pushed a commit to Ankurdeewan/airflow that referenced this pull request Mar 15, 2026
…ter (apache#61701)

Co-authored-by: Shahar Epstein <60007259+shahar1@users.noreply.github.com>
radhwene pushed a commit to radhwene/airflow that referenced this pull request Mar 21, 2026
…ter (apache#61701)

Co-authored-by: Shahar Epstein <60007259+shahar1@users.noreply.github.com>
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