Created
February 14, 2021 11:13
-
-
Save SiddharthPant/16a4d758f1c16f57fdedf9a7b09706f8 to your computer and use it in GitHub Desktop.
Celery logging done right
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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