From f0f327bbfe1caae6d11fbe20a3b5b96eed1704cf Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Wed, 26 Sep 2012 19:56:21 +0200 Subject: Fixed #18993 -- 'django' logger logs to console when DEBUG=True Thanks Preston Holmes for the review. --- django/utils/log.py | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'django') diff --git a/django/utils/log.py b/django/utils/log.py index c111512fe8..9e07961221 100644 --- a/django/utils/log.py +++ b/django/utils/log.py @@ -24,18 +24,25 @@ except ImportError: getLogger = logging.getLogger -# Default logging for Django. This sends an email to -# the site admins on every HTTP 500 error. All other log -# records are sent to the bit bucket. +# Default logging for Django. This sends an email to the site admins on every +# HTTP 500 error. Depending on DEBUG, all other log records are either sent to +# the console (DEBUG=True) or discarded by mean of the NullHandler (DEBUG=False). DEFAULT_LOGGING = { 'version': 1, 'disable_existing_loggers': False, 'filters': { 'require_debug_false': { '()': 'django.utils.log.RequireDebugFalse', - } + }, + 'require_debug_true': { + '()': 'django.utils.log.RequireDebugTrue', + }, }, 'handlers': { + 'console':{ + 'level': 'INFO', + 'class': 'logging.StreamHandler', + }, 'null': { 'class': 'django.utils.log.NullHandler', }, @@ -47,12 +54,13 @@ DEFAULT_LOGGING = { }, 'loggers': { 'django': { - 'handlers': ['null'], + 'handlers': ['console'], + 'filters': ['require_debug_true'], }, 'django.request': { 'handlers': ['mail_admins'], 'level': 'ERROR', - 'propagate': True, + 'propagate': False, }, } } @@ -130,3 +138,8 @@ class CallbackFilter(logging.Filter): class RequireDebugFalse(logging.Filter): def filter(self, record): return not settings.DEBUG + + +class RequireDebugTrue(logging.Filter): + def filter(self, record): + return settings.DEBUG -- cgit v1.3