Commit 343004c4 authored by Carl Meyer's avatar Carl Meyer
Browse files

Fixed #16568 -- Added RequireDebugFalse filter to prevent sending 500 error...

Fixed #16568 -- Added RequireDebugFalse filter to prevent sending 500 error emails when DEBUG is True in projects with no explicit LOGGING setting. Thanks to Andreas Pelme for report and patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16840 bcc190cf-cafb-0310-a4f2-bffc1f526a37
parent f9dad46d
Loading
Loading
Loading
Loading
+2 −7
Original line number Diff line number Diff line
@@ -199,13 +199,8 @@ def compat_patch_logging_config(logging_config):
        while filter_name in filters:
            filter_name = filter_name + "_"

        def _callback(record):
            from django.conf import settings
            return not settings.DEBUG

        filters[filter_name] = {
            "()": "django.utils.log.CallbackFilter",
            "callback": _callback
            "()": "django.utils.log.RequireDebugFalse",
        }

        logging_config["handlers"]["mail_admins"]["filters"] = [filter_name]
+2 −2
Original line number Diff line number Diff line
@@ -514,13 +514,13 @@ LOGGING_CONFIG = 'django.utils.log.dictConfig'
# The default logging configuration. This sends an email to
# the site admins on every HTTP 500 error. All other log
# records are sent to the bit bucket.

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'filters': {
        'require_debug_false': {
            '()': 'django.utils.log.CallbackFilter',
            'callback': lambda r: not DEBUG
            '()': 'django.utils.log.RequireDebugFalse',
        }
    },
    'handlers': {
+1 −2
Original line number Diff line number Diff line
@@ -128,8 +128,7 @@ LOGGING = {
    'disable_existing_loggers': False,
    'filters': {
        'require_debug_false': {
            '()': 'django.utils.log.CallbackFilter',
            'callback': lambda r: not DEBUG
            '()': 'django.utils.log.RequireDebugFalse'
        }
    },
    'handlers': {
+6 −1
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ logger = getLogger('django')
if not logger.handlers:
    logger.addHandler(NullHandler())


class AdminEmailHandler(logging.Handler):
    """An exception log handler that emails log entries to site admins.

@@ -82,8 +83,12 @@ class CallbackFilter(logging.Filter):
    def __init__(self, callback):
        self.callback = callback


    def filter(self, record):
        if self.callback(record):
            return 1
        return 0


class RequireDebugFalse(logging.Filter):
    def filter(self, record):
        return not settings.DEBUG
+1 −2
Original line number Diff line number Diff line
@@ -593,8 +593,7 @@ to :class:`django.utils.log.AdminEmailHandler` to prevent admin error emails in

   'filters': {
        'require_debug_false': {
            '()': 'django.utils.log.CallbackFilter',
            'callback': lambda r: not DEBUG
            '()': 'django.utils.log.RequireDebugFalse'
        }
    },
    'handlers': {
Loading