Ticket #16288: debug_logging.diff

File debug_logging.diff, 2.5 KB (added by mattbennett, 13 years ago)
  • django/conf/project_template/settings.py

     
    125125
    126126# A sample logging configuration. The only tangible logging
    127127# performed by this configuration is to send an email to
    128 # the site admins on every HTTP 500 error.
     128# the site admins on every HTTP 500 error when DEBUG=False.
    129129# See http://docs.djangoproject.com/en/dev/topics/logging for
    130130# more details on how to customize your logging configuration.
    131131LOGGING = {
    132132    'version': 1,
    133133    'disable_existing_loggers': False,
     134    'filters': {
     135        'require_debug_false': {
     136            '()': 'django.utils.log.DebugFalseFilter'
     137        }
     138    },
    134139    'handlers': {
    135140        'mail_admins': {
    136141            'level': 'ERROR',
     142            'filters': ['require_debug_false'],
    137143            'class': 'django.utils.log.AdminEmailHandler'
    138144        }
    139145    },
  • django/core/handlers/base.py

     
    198198        if settings.DEBUG_PROPAGATE_EXCEPTIONS:
    199199            raise
    200200
    201         if settings.DEBUG:
    202             from django.views import debug
    203             return debug.technical_500_response(request, *exc_info)
    204 
    205201        logger.error('Internal Server Error: %s' % request.path,
    206202            exc_info=exc_info,
    207203            extra={
     
    210206            }
    211207        )
    212208
     209        if settings.DEBUG:
     210            from django.views import debug
     211            return debug.technical_500_response(request, *exc_info)
     212       
    213213        # If Http500 handler is not installed, re-raise last exception
    214214        if resolver.urlconf_module is None:
    215215            raise exc_info[1], None, exc_info[2]
  • django/utils/log.py

     
    7070        reporter = ExceptionReporter(request, is_email=True, *exc_info)
    7171        html_message = self.include_html and reporter.get_traceback_html() or None
    7272        mail.mail_admins(subject, message, fail_silently=True, html_message=html_message)
     73
     74
     75class DebugFalseFilter(logging.Filter):
     76    """A filter that disables a logger or handler when debug mode is enabled."""
     77    def filter(self, record):
     78        if settings.DEBUG:
     79            return 0
     80        return 1
Back to Top