사용 장고에 대해이 핸들러 :
from raven.contrib.django.handlers import SentryHandler as BaseSentryHandler
from raven.utils.stacks import iter_stack_frames
class SentryHandler(BaseSentryHandler):
def emit(self, record):
if not getattr(record, 'stack', None):
record.stack = self._get_stack(record)
return super(SentryHandler, self).emit(record)
def _get_targetted_stack(self, stack):
return stack
def _get_stack(self, record):
"""Remove non-interesting parts of the stack.
"""
stack = iter_stack_frames()
frames = []
for item in stack:
if isinstance(item, (list, tuple)):
frame, lineno = item
else:
frame, lineno = item, item.f_lineno
frames.append((frame, lineno))
# remove parts after the `logging` module was entered
for frame_no in reversed(xrange(len(frames))):
frame, line_no = frames[frame_no]
module_name = getattr(frame, 'f_globals', {}).get('__name__', '')
if module_name.startswith('logging'):
del frames[:frame_no + 1]
break
else:
# the entry point to `logging` module was not found
return frames
return frames