Question

Now that django-sentry has become a standalone server (and is fantastic) I'm trying to port my apps over to use it.

I have set up a standalone server configured a django application to log using django 1.3's logging dictionary conf as per the raven docs. I can't seem to get any celery tasks to log to the sentry server (they do get printed out to the console though).

I'm not really sure what I should be doing? I have included raven.contrib.django.celery in my `INSTALLED_APPS'.

Uncaught exceptions are being sent to sentry, as are custom logging message via:

import logging
logger = logging.getLogger(__name__)
...
logger.info("Logged Message")    
Was it helpful?

Solution

You need to add this:

'celery': {
        'level': 'WARNING',
        'handlers': ['sentry'],
        'propagate': False,
    },

To your loggers in the variable LOGGING in your settings.

something like:

# the site admins on every HTTP 500 error.
# See http://docs.djangoproject.com/en/dev/topics/logging for
# more details on how to customize your logging configuration.
LOGGING = {
    'version': 1,
    'disable_existing_loggers': True,
    'root': {
        'level': 'WARNING',
        'handlers': ['sentry'],
    },
    'formatters': {
        'verbose': {
            'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %    (message)s'
        },
    },
    'handlers': {
        'sentry': {
            'level': 'DEBUG',
            'class': 'raven.contrib.django.handlers.SentryHandler',
        },
        'console': {
            'level': 'DEBUG',
            'class': 'logging.StreamHandler',
            'formatter': 'verbose'
        }
    },
    'loggers': {
        'django.db.backends': {
            'level': 'ERROR',
            'handlers': ['console'],
            'propagate': False,
        },
        'raven': {
            'level': 'DEBUG',
            'handlers': ['console'],
            'propagate': False,
        },
        'sentry.errors': {
            'level': 'DEBUG',
            'handlers': ['console'],
            'propagate': False,
        },
        'celery': {
            'level': 'WARNING',
            'handlers': ['sentry'],
            'propagate': False,
        },
    },
}

OTHER TIPS

Since Raven 5+, you may need to add a setting to your Django project, like described in Sentry logging in Django/Celery stopped working

CELERYD_HIJACK_ROOT_LOGGER = False

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top