本文介绍了Sentry django配置-记录器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用简单的日志记录,并希望向Sentry发送错误/异常.
I am trying to use simple logging and want to send errors/exceptions to Sentry.
我根据文档配置了哨兵,并在我的dev(python manage.py raven test
)上成功运行了测试
I configured the Sentry as per the document and run the test successfully on my dev(python manage.py raven test
)
我在哨兵文档中添加了日志记录配置Django设置
I added the Logging configuration as in Sentry documentation to a Django settings
当我将此代码放入View时,它根本不起作用
When I put this code in my View, then it doesn't work at all
import logging
logger = logging.getLogger(__name__)
logger.error('There was an error, with a stacktrace!', extra={
'stack': True,
})
也许我缺少了一些东西
感谢您的帮助
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,
},
},
}
推荐答案
与Django集成需要在settings.py中使用特殊的Raven Django应用和RAVEN_CONFIG:
Integration with Django requires special Raven Django app and RAVEN_CONFIG in settings.py:
INSTALLED_APPS = (
'raven.contrib.django.raven_compat',
)
RAVEN_CONFIG = {
'dsn': 'https://<key>:<secret>@sentry.io/<project>',
}
您设置了它们吗?
这篇关于Sentry django配置-记录器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!