mirror of
https://github.com/django/django.git
synced 2025-11-03 05:13:23 +00:00
Fixed #16288 -- Enabled django.request exception logger regardless of DEBUG setting.
Thanks Matt Bennett for report and draft patch; Vinay Sajip and Russell Keith-Magee for review. git-svn-id: http://code.djangoproject.com/svn/django/trunk@16444 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
9eb2afddfa
commit
43503b093a
12 changed files with 285 additions and 5 deletions
|
|
@ -210,6 +210,11 @@ their deprecation, as per the :ref:`Django deprecation policy
|
|||
* Legacy ways of calling
|
||||
:func:`~django.views.decorators.cache.cache_page` will be removed.
|
||||
|
||||
* The backward-compatibility shim to automatically add a debug-false
|
||||
filter to the ``'mail_admins'`` logging handler will be removed. The
|
||||
:setting:`LOGGING` setting should include this filter explicitly if
|
||||
it is desired.
|
||||
|
||||
* 2.0
|
||||
* ``django.views.defaults.shortcut()``. This function has been moved
|
||||
to ``django.contrib.contenttypes.views.shortcut()`` as part of the
|
||||
|
|
|
|||
|
|
@ -387,3 +387,44 @@ releases 8.0 and 8.1 was near (November 2010.)
|
|||
|
||||
Django 1.4 takes that policy further and sets 8.2 as the minimum PostgreSQL
|
||||
version it officially supports.
|
||||
|
||||
Request exceptions are now always logged
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
When :doc:`logging support </topics/logging/>` was added to Django in 1.3, the
|
||||
admin error email support was moved into the
|
||||
:class:`django.utils.log.AdminEmailHandler`, attached to the
|
||||
``'django.request'`` logger. In order to maintain the established behavior of
|
||||
error emails, the ``'django.request'`` logger was called only when
|
||||
:setting:`DEBUG` was `False`.
|
||||
|
||||
To increase the flexibility of request-error logging, the ``'django.request'``
|
||||
logger is now called regardless of the value of :setting:`DEBUG`, and the
|
||||
default settings file for new projects now includes a separate filter attached
|
||||
to :class:`django.utils.log.AdminEmailHandler` to prevent admin error emails in
|
||||
`DEBUG` mode::
|
||||
|
||||
'filters': {
|
||||
'require_debug_false': {
|
||||
'()': 'django.utils.log.CallbackFilter',
|
||||
'callback': lambda r: not DEBUG
|
||||
}
|
||||
},
|
||||
'handlers': {
|
||||
'mail_admins': {
|
||||
'level': 'ERROR',
|
||||
'filters': ['require_debug_false'],
|
||||
'class': 'django.utils.log.AdminEmailHandler'
|
||||
}
|
||||
},
|
||||
|
||||
If your project was created prior to this change, your :setting:`LOGGING`
|
||||
setting will not include this new filter. In order to maintain
|
||||
backwards-compatibility, Django will detect that your ``'mail_admins'`` handler
|
||||
configuration includes no ``'filters'`` section, and will automatically add
|
||||
this filter for you and issue a pending-deprecation warning. This will become a
|
||||
deprecation warning in Django 1.5, and in Django 1.6 the
|
||||
backwards-compatibility shim will be removed entirely.
|
||||
|
||||
The existence of any ``'filters'`` key under the ``'mail_admins'`` handler will
|
||||
disable this backward-compatibility shim and deprecation warning.
|
||||
|
|
|
|||
|
|
@ -501,3 +501,37 @@ Python logging module.
|
|||
:ref:`Filtering error reports<filtering-error-reports>`.
|
||||
|
||||
.. _django-sentry: http://pypi.python.org/pypi/django-sentry
|
||||
|
||||
|
||||
Filters
|
||||
-------
|
||||
|
||||
Django provides one log filter in addition to those provided by the
|
||||
Python logging module.
|
||||
|
||||
.. class:: CallbackFilter(callback)
|
||||
|
||||
.. versionadded:: 1.4
|
||||
|
||||
This filter accepts a callback function (which should accept a single
|
||||
argument, the record to be logged), and calls it for each record that passes
|
||||
through the filter. Handling of that record will not proceed if the callback
|
||||
returns False.
|
||||
|
||||
This filter is used as follows in the default :setting:`LOGGING`
|
||||
configuration to ensure that the :class:`AdminEmailHandler` only sends error
|
||||
emails to admins when :setting:`DEBUG` is `False`::
|
||||
|
||||
'filters': {
|
||||
'require_debug_false': {
|
||||
'()': 'django.utils.log.CallbackFilter',
|
||||
'callback': lambda r: not DEBUG
|
||||
}
|
||||
},
|
||||
'handlers': {
|
||||
'mail_admins': {
|
||||
'level': 'ERROR',
|
||||
'filters': ['require_debug_false'],
|
||||
'class': 'django.utils.log.AdminEmailHandler'
|
||||
}
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue