Fix logging configuration for Celery tasks (#5563)

This commit is contained in:
Pulse-Mind 2025-01-02 21:44:08 +01:00 committed by GitHub
parent df2bd97a24
commit 411e92cf9d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 0 deletions

View File

@ -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")
@ -13,5 +14,15 @@ app = Celery("{{cookiecutter.project_slug}}")
# 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()

View File

@ -327,6 +327,8 @@ CELERY_BEAT_SCHEDULER = "django_celery_beat.schedulers:DatabaseScheduler"
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