I may be a bit late on the train, but I wanted to use Sentry and Raven for logging in Django.
I set up sentry and raven to the point, where I ran the test for raven and it works.
So now I want to send my debug messages over to sentry, but how would I do this?
settings.py
RAVEN_CONFIG = {
'dsn': 'http://code4@mydomain:9000/2',
# If you are using git, you can also automatically configure the
# release based on the git info.
'release': raven.fetch_git_sha(BASE_DIR),
}
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'verbose': {
'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s'
},
},
'handlers': {
'sentry': {
'level': 'WARNING',
'class': 'raven.contrib.django.raven_compat.handlers.SentryHandler',
},
'console': {
'level': 'WARNING',
'class': 'logging.StreamHandler',
'formatter': 'verbose'
}
},
'loggers': {
'django': {
'handlers': ['sentry'],
'level': 'DEBUG',
'propagate': True,
},
'raven': {
'level': 'DEBUG',
'handlers': ['sentry'],
'propagate': False,
},
'sentry.errors': {
'level': 'DEBUG',
'handlers': ['sentry'],
'propagate': False,
},
}
}
view.py
import logger
from raven.contrib.django.models import get_client
client = get_client()
client.captureException()
logger = logging.getLogger(__name__)
def my_view(request):
[...]
logger.error('There was some crazy error', exc_info=True, extra={
# Optionally pass a request and we'll grab any information we can
'request': request,
})
[...]
At this point it just logs errors and exceptions but wont send me this error message...
How is the right way to use raven and sentry? The docs are totaly not helping and my google foo left me also. Any tips or helpfull tutorials?
You have 3 loggers defined: django
, raven
and sentry.errors
. When you call logging.getLogger(__name__)
you actually create a "throw-away" one, because your ___name__
doesn't match any of above.
You should either use the raven
logger...
logger = logging.getLogger('raven')
logger.debug('Hola!')
...or setup your own:
LOGGING = {
# ...
'loggers': {
# ...
'yourapp': {
'level': 'debug',
'handlers': ['sentry'],
'propagate': False,
},
}
}
and then in yourapp/views.py
:
logger = logging.getLogger(__name__)
logger.debug('Hola!')