From 18a69aff6265651818cba94e5bfa0668db780424 Mon Sep 17 00:00:00 2001 From: fravetier Date: Fri, 29 Nov 2024 13:46:24 +0100 Subject: [PATCH] Fix #5559 Use log of the application into Celery tasks --- {{cookiecutter.project_slug}}/config/celery_app.py | 10 ++++++++++ {{cookiecutter.project_slug}}/config/settings/base.py | 2 ++ 2 files changed, 12 insertions(+) diff --git a/{{cookiecutter.project_slug}}/config/celery_app.py b/{{cookiecutter.project_slug}}/config/celery_app.py index 0728a649e0..756f8d41ff 100644 --- a/{{cookiecutter.project_slug}}/config/celery_app.py +++ b/{{cookiecutter.project_slug}}/config/celery_app.py @@ -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,14 @@ # should have a `CELERY_` prefix. app.config_from_object("django.conf:settings", namespace="CELERY") + +@setup_logging.connect +def config_loggers(*args, **kwargs): + from django.conf import settings + from logging.config import dictConfig + + dictConfig(settings.LOGGING) + + # Load task modules from all registered Django app configs. app.autodiscover_tasks() diff --git a/{{cookiecutter.project_slug}}/config/settings/base.py b/{{cookiecutter.project_slug}}/config/settings/base.py index ed34a90ea8..07da3b8097 100644 --- a/{{cookiecutter.project_slug}}/config/settings/base.py +++ b/{{cookiecutter.project_slug}}/config/settings/base.py @@ -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