Django / Celery logging stopped working

I have no idea what happened. So far, registration has worked fine (and I relied on it), but it seems to have stopped. I wrote a small test function (which doesn't work either):

core.tasks.py

import logging from celery.utils.log import get_task_logger logger = get_task_logger(__name__) logger.setLevel(logging.DEBUG) @app.task def log_error(): logger.error('ERROR') 

settings.py

 INSTALLED_APPS += ( 'raven.contrib.django.raven_compat', ) LOGGING = { 'version': 1, 'disable_existing_loggers': True, 'root': { 'level': 'INFO', #If set to DEBUG, prints ALL DJANGO debug logs. 'handlers': ['console', 'sentry'], }, 'formatters': { 'simple': { 'format': '%(levelname)s %(message)s' }, }, 'handlers': { #log everything to the console 'console':{ 'level':'DEBUG', 'class':'logging.StreamHandler', 'formatter': 'simple' }, #logs directly to sentry 'sentry': { 'level': 'ERROR', 'class': 'raven.contrib.django.raven_compat.handlers.SentryHandler', #'class': 'raven.contrib.django.handlers.SentryHandler', #I have tried both }, }, 'loggers': { 'django.request':{ 'handlers': ['console', 'sentry'], 'level': 'DEBUG', 'propagate': False, }, 'celery.task':{ 'handlers': ['console', 'sentry'], 'level': 'DEBUG', 'propagate': False, }, #this is the logger for celery itself 'celery':{ 'handlers': ['console', 'sentry'], 'level': 'ERROR', 'propagate': False, }, }, } from logging.config import dictConfig dictConfig(LOGGING) 

Doing the following in Django shell logs on the console, but it did not reach Sentry:

 from core import tasks tasks.log_error.delay() 

It works when performing a task synchronously:

 tasks.log_error() 

Help!

Django == 1.6.2, raven == 5.0.0, sentry == 6.3.2, Python 2.7.3

+4
django logging celery sentry raven
source share
1 answer

I had to add

 CELERYD_HIJACK_ROOT_LOGGER=False 

to my Django.py settings.

I really don't understand why I should explicitly say celery so as not to grab the root log.

+8
source share

All Articles