我可能有点晚上了这趟车,但我想在Django中使用Sentry和Raven进行日志记录。
我已经将Sentry和Raven设置到了某个程度,我运行了Raven的测试,它可以正常工作。
现在我想将我的调试信息发送到Sentry,但我该如何做呢?
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,
},
}
}
视图.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,
})
[...]
在这一点上,它只记录错误和异常,但无法将此错误消息发送给我...如何正确使用raven和sentry?文档完全没有帮助,我的谷歌foo也没能找到答案。有什么提示或有用的教程吗?