擅长:python、mysql、java
<p>您可以编写一个自定义的<a href="https://docs.python.org/2/library/logging.html#handler-objects" rel="nofollow">Handler</a>,它使用<code>django.views.debug.ExceptionReporter</code>来格式化异常。在</p>
<p><code>ExceptionReporter</code>的用法示例:</p>
<pre><code>from django.views.debug import ExceptionReporter
# exc_type, exc_value, traceback are a standard exception
# tuple as returned by sys.exc_info
reporter = ExceptionReporter(request, exc_type, exc_value, traceback)
html_report = reporter.get_traceback_html()
text_report = reporter.get_traceback_text()
</code></pre>
<p><code>ExceptionReporter</code>将使用由<code>DEFAULT_EXCEPTION_REPORTER_FILTER</code>设置定义的<code>ExceptionReporterFilter</code>,默认情况下是<code>SafeExceptionReporterFilter</code>。在</p>
<p>查看<code>AdminEmailHandler</code>的<a href="https://github.com/django/django/blob/1.8/django%2Futils%2Flog.py#L89" rel="nofollow">implementation</a>,了解如何创建自定义<code>Handler</code>。在</p>