from __future__ import absolute_import from celery import Celery from

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from __future__ import absolute_import
from celery import Celery
from django.conf import settings
import os
import logging
from celery.signals import after_setup_logger
os.environ['DJANGO_SETTINGS_MODULE'] = 'project.settings'
app = Celery('celery', include=['engine.task_key'])
app.config_from_object(settings)
log_path = os.path.join(BASE_DIR, 'var/log/celery.error.log')
handler = logging.FileHandler(log_path, 'a')
handler.setLevel(logging.WARNING)
def setup_extra_logging(format, **kwargs):
logger = logging.getLogger()
if not handler in logger.handlers:
handler.setFormatter(logging.Formatter(format))
logger.addHandler(handler)
after_setup_logger.connect(setup_extra_logging)