diff options
| author | Pavel Lysak <p.lysak@corp.mail.ru> | 2019-09-07 20:08:12 +0300 |
|---|---|---|
| committer | Carlton Gibson <carlton@noumenal.es> | 2020-01-16 15:25:49 +0100 |
| commit | 13e4abf83e5129b44c771b2204809792087abda4 (patch) | |
| tree | 4a1ae01aef949cde3210a62127a985258aae245b /docs | |
| parent | a5a28de89dabfa03302a5893102b6f1a7c7861a1 (diff) | |
Fixed #30752 -- Allowed using ExceptionReporter subclasses in error reports.
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/howto/error-reporting.txt | 56 | ||||
| -rw-r--r-- | docs/ref/settings.txt | 14 | ||||
| -rw-r--r-- | docs/releases/3.1.txt | 4 |
3 files changed, 74 insertions, 0 deletions
diff --git a/docs/howto/error-reporting.txt b/docs/howto/error-reporting.txt index e145897b2a..13043cf387 100644 --- a/docs/howto/error-reporting.txt +++ b/docs/howto/error-reporting.txt @@ -305,6 +305,62 @@ following attributes and methods: traceback frame. Sensitive values are replaced with :attr:`cleansed_substitute`. +.. versionadded:: 3.1 + +If you need to customize error reports beyond filtering you may specify a +custom error reporter class by defining the +:setting:`DEFAULT_EXCEPTION_REPORTER` setting:: + + DEFAULT_EXCEPTION_REPORTER = 'path.to.your.CustomExceptionReporter' + +The exception reporter is responsible for compiling the exception report data, +and formatting it as text or HTML appropriately. (The exception reporter uses +:setting:`DEFAULT_EXCEPTION_REPORTER_FILTER` when preparing the exception +report data.) + +Your custom reporter class needs to inherit from +:class:`django.views.debug.ExceptionReporter`. + +.. class:: ExceptionReporter + + .. method:: get_traceback_data() + + Return a dictionary containing traceback information. + + This is the main extension point for customizing exception reports, for + example:: + + from django.views.debug import ExceptionReporter + + + class CustomExceptionReporter(ExceptionReporter): + def get_traceback_data(self): + data = super().get_traceback_data() + # ... remove/add something here ... + return data + + .. method:: get_traceback_html() + + Return HTML version of exception report. + + Used for HTML version of debug 500 HTTP error page. + + .. method:: get_traceback_text() + + Return plain text version of exception report. + + Used for plain text version of debug 500 HTTP error page and email + reports. + +As with the filter class, you may control which exception reporter class to use +within any given view by setting the ``HttpRequest``’s +``exception_reporter_class`` attribute:: + + def my_view(request): + if request.user.is_authenticated: + request.exception_reporter_class = CustomExceptionReporter() + ... + .. seealso:: You can also set up custom error reporting by writing a custom piece of diff --git a/docs/ref/settings.txt b/docs/ref/settings.txt index 51bbba35f0..917ffeebb4 100644 --- a/docs/ref/settings.txt +++ b/docs/ref/settings.txt @@ -1250,6 +1250,19 @@ Default: ``'utf-8'`` Default charset to use for all ``HttpResponse`` objects, if a MIME type isn't manually specified. Used when constructing the ``Content-Type`` header. +.. setting:: DEFAULT_EXCEPTION_REPORTER + +``DEFAULT_EXCEPTION_REPORTER`` +------------------------------ + +.. versionadded:: 3.1 + +Default: ``'``:class:`django.views.debug.ExceptionReporter`\ ``'`` + +Default exception reporter class to be used if none has been assigned to the +:class:`~django.http.HttpRequest` instance yet. See +:ref:`custom-error-reports`. + .. setting:: DEFAULT_EXCEPTION_REPORTER_FILTER ``DEFAULT_EXCEPTION_REPORTER_FILTER`` @@ -3537,6 +3550,7 @@ Email Error reporting --------------- +* :setting:`DEFAULT_EXCEPTION_REPORTER` * :setting:`DEFAULT_EXCEPTION_REPORTER_FILTER` * :setting:`IGNORABLE_404_URLS` * :setting:`MANAGERS` diff --git a/docs/releases/3.1.txt b/docs/releases/3.1.txt index 064aadd34a..ced98c2e47 100644 --- a/docs/releases/3.1.txt +++ b/docs/releases/3.1.txt @@ -173,6 +173,10 @@ Error Reporting :setting:`DEFAULT_EXCEPTION_REPORTER_FILTER` when applying settings filtering. +* The new :setting:`DEFAULT_EXCEPTION_REPORTER` allows providing a + :class:`django.views.debug.ExceptionReporter` subclass to customize exception + report generation. See :ref:`custom-error-reports` for details. + File Storage ~~~~~~~~~~~~ |
