raven有很多集成,包括python日志记录。一方面,twisted不使用python的日志记录。而在另一方面,没有直接整合乌鸦的扭曲。
那么目前在基于扭曲的设置中使用raven的最佳做法是什么?
答案 0 :(得分:10)
raven
的{{1}},而在调用日志观察者时并非总是如此。因此,将异常信息从记录的captureException
中拉出来:
Failure
答案 1 :(得分:2)
user1252307答案是一个很好的开始,但在哨兵方面,你得到一个相对无益的字典,没有堆栈跟踪。
如果您正在尝试查看和追踪意外异常,请尝试对log_sentry函数进行此小改动:
from twisted.python import log
from raven import Client
client = Client(dsn='twisted+http://YOUR_DSN_HERE')
def log_sentry(dictionary):
if dictionary.get('isError'):
if 'failure' in dictionary:
client.captureException() # Send the current exception info to Sentry.
else:
#format the dictionary in whatever way you want
client.captureMessage(dictionary)
log.addObserver(log_sentry)
可能有更好的方法来过滤基于非异常的错误消息,这可能会尝试发出在存在非异常故障的情况下不存在的异常信息。
答案 2 :(得分:1)
from twisted.python import log
from raven import Client
client = Client(dsn='twisted+http://YOUR_DSN_HERE')
def log_sentry(dictionary):
if dictionary.get('isError'):
#format the dictionary in whatever way you want
client.captureMessage(dictionary)
log.addObserver(log_sentry)