Add logging configuration to prevent Celery from overriding Django's logging setup
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import os
|
||||
from celery import Celery
|
||||
from celery.signals import setup_logging
|
||||
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mnemosyne.settings")
|
||||
|
||||
@@ -10,3 +11,18 @@ app.config_from_object("django.conf:settings", namespace="CELERY")
|
||||
|
||||
# Auto-discover tasks from all registered Django app configs
|
||||
app.autodiscover_tasks()
|
||||
|
||||
|
||||
@setup_logging.connect
|
||||
def config_loggers(*args, **kwargs):
|
||||
"""
|
||||
Prevent Celery from overriding Django's logging configuration.
|
||||
|
||||
Celery normally replaces all logging handlers at worker startup. Connecting
|
||||
to this signal tells Celery to skip its own logging setup entirely, so the
|
||||
LOGGING config in settings.py remains in effect for worker processes.
|
||||
"""
|
||||
from logging.config import dictConfig
|
||||
from django.conf import settings
|
||||
|
||||
dictConfig(settings.LOGGING)
|
||||
|
||||
Reference in New Issue
Block a user