我想用sentry记录测试异常。所以我配置了它:
# tests/__init__.py
from raven import Client
from raven.conf import setup_logging
from raven.handlers.logging import SentryHandler
client = Client(dsn='here goes dsn')
handler = SentryHandler(client, level=logging.ERROR)
setup_logging(handler)
当我运行测试时:
^{pr2}$我在sentry仪表板中都看到了:记录器错误和异常
当日志记录级别为“关键”时,不会显示任何内容。在
那么,有没有一种方法只记录异常,而不记录常规日志?在
Sentry目前没有提供一种方式来表示“只捕获附加了异常的日志事件”,但是您可以为它编写一个
logging.Filter
。Python文档有点稀疏,但下面是一个过滤器示例:https://docs.python.org/2/howto/logging-cookbook.html#using-filters-to-impart-contextual-information
基本上,您需要检测条目上是否存在异常信息,如果存在,则返回True(告诉它捕获条目)。在
相关问题 更多 >
编程相关推荐