Celery logger configuration

前端 未结 3 1013
花落未央
花落未央 2021-02-13 00:03

I\'m using Django 1.10, python 3.5 and celery 4.1.0 I\'m trying to log celery tasks info into a file. So I tried as suggested in celery documentation -

from cele         


        
3条回答
  •  后悔当初
    2021-02-13 00:17

    For what it's worth, this is how I configured celery to use my Django logging settings:

    from __future__ import absolute_import, unicode_literals
    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', 'app.settings')
    
    app = Celery('app')
    
    # 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, **kwags):
        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()
    

    That was about it - after that change my django logging settings worked for celery, including the logging I had setup to send log messages over to slack.

提交回复
热议问题