Do i need to explicitly log messages for sentry to work in Django
I have installed Sentry for messages logging. I am new to sentry so i don't how it works.
Does it logs only those messages which put in my files with logger ("error something")
or whatever error occurs it automatically logs it
Suppose i have not written any log statement in my view. Now if i get any exception then will sentry logs it or i have to program every exception for sent开发者_如何转开发ry
is there any way to automatically logs all error without entering any code because i don't know what type of exceptions can occur
Sentry auto catches all exceptions and logs them. As for logging itself (using logger), it doesn't catch those by default. You have to set it up.
You may view how to setup logging here. Warning: it does seem difficult do to at first.
Edit: Excerpt from official docs (07/26/2018):
Integration with logging: To integrate with the standard library’s logging module, and send all ERROR and above messages to sentry, the following config can be used:
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': 'ERROR', # To capture more than ERROR, change to WARNING, INFO, etc.
'class': 'raven.contrib.django.raven_compat.handlers.SentryHandler',
'tags': {'custom-tag': 'x'},
},
'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,
},
},
}
Usage: Logging usage works the same way as it does outside of Django, with the addition of an optional request key in the extra data:
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,
})
精彩评论