Skip to content

Instantly share code, notes, and snippets.

@SiddharthPant
Created February 14, 2021 11:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SiddharthPant/16a4d758f1c16f57fdedf9a7b09706f8 to your computer and use it in GitHub Desktop.
Save SiddharthPant/16a4d758f1c16f57fdedf9a7b09706f8 to your computer and use it in GitHub Desktop.
Celery logging done right
import os
from celery import Celery
from celery.signals import setup_logging # noqa
# set the default Django settings module for the 'celery' program.
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "src.settings")
app = Celery("src")
# Using a string here means the worker doesn't have to serialize
# the configuration object to child processes.
# - namespace='CELERY' means all celery-related configuration keys
# 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 # noqa
from django.conf import settings # noqa
dictConfig(settings.LOGGING)
# Load task modules from all registered Django app configs.
app.autodiscover_tasks()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment