我可能在火车上有点迟了,但我想用Sentry和Raven登录Django.
我设立了哨兵和乌鸦,在那里我为乌鸦进行了测试并且它有效.
所以现在我想将调试信息发送到哨兵,但我该怎么做呢?
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, }) [...]
此时它只记录错误和异常,但不会向我发送此错误消息...
如何正确使用乌鸦和哨兵?文档完全没有帮助,我的谷歌foo也离开了我.任何提示或有用的教程?
你有3个记录器定义:django
,raven
和sentry.errors
.当你打电话时,logging.getLogger(__name__)
你实际上会创建一个"扔掉"的,因为你___name__
的上述任何一个都不匹配.
你应该使用raven
记录器......
logger = logging.getLogger('raven') logger.debug('Hola!')
...或自己设置:
LOGGING = { # ... 'loggers': { # ... 'yourapp': { 'level': 'debug', 'handlers': ['sentry'], 'propagate': False, }, } }
然后在yourapp/views.py
:
logger = logging.getLogger(__name__) logger.debug('Hola!')