Skip to content

Commit

Permalink
Fix logging configuration for Celery tasks (#5563)
Browse files Browse the repository at this point in the history
  • Loading branch information
pulse-mind authored Jan 2, 2025
1 parent df2bd97 commit 411e92c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
11 changes: 11 additions & 0 deletions {{cookiecutter.project_slug}}/config/celery_app.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os

from celery import Celery
from celery.signals import setup_logging

# set the default Django settings module for the 'celery' program.
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings.local")
Expand All @@ -13,5 +14,15 @@
# should have a `CELERY_` prefix.
app.config_from_object("django.conf:settings", namespace="CELERY")


@setup_logging.connect
def config_loggers(*args, **kwargs):
from logging.config import dictConfig

from django.conf import settings

dictConfig(settings.LOGGING)


# Load task modules from all registered Django app configs.
app.autodiscover_tasks()
2 changes: 2 additions & 0 deletions {{cookiecutter.project_slug}}/config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,8 @@
CELERY_WORKER_SEND_TASK_EVENTS = True
# https://docs.celeryq.dev/en/stable/userguide/configuration.html#std-setting-task_send_sent_event
CELERY_TASK_SEND_SENT_EVENT = True
# https://cheat.readthedocs.io/en/latest/django/celery.html
CELERYD_HIJACK_ROOT_LOGGER = False

{%- endif %}
# django-allauth
Expand Down

0 comments on commit 411e92c

Please sign in to comment.