summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2012-09-24 22:30:38 +0200
committerClaude Paroz <claude@2xlibre.net>2012-09-29 22:56:18 +0200
commita014ddfef2f606471f25c756d97b3b50fcbd9e91 (patch)
tree387712a6b25cba824d7797f9214a41f374f83cea /django
parent15202baace1453e7576806f13d137ae930de6dcb (diff)
Combined Django DEFAULT_LOGGING with user LOGGING config
Refs #18993.
Diffstat (limited to 'django')
-rw-r--r--django/conf/__init__.py12
-rw-r--r--django/conf/global_settings.py29
-rw-r--r--django/utils/log.py39
3 files changed, 43 insertions, 37 deletions
diff --git a/django/conf/__init__.py b/django/conf/__init__.py
index d636ff0b6c..7452013671 100644
--- a/django/conf/__init__.py
+++ b/django/conf/__init__.py
@@ -55,16 +55,20 @@ class LazySettings(LazyObject):
Setup logging from LOGGING_CONFIG and LOGGING settings.
"""
if self.LOGGING_CONFIG:
+ from django.utils.log import DEFAULT_LOGGING
# First find the logging configuration function ...
logging_config_path, logging_config_func_name = self.LOGGING_CONFIG.rsplit('.', 1)
logging_config_module = importlib.import_module(logging_config_path)
logging_config_func = getattr(logging_config_module, logging_config_func_name)
- # Backwards-compatibility shim for #16288 fix
- compat_patch_logging_config(self.LOGGING)
+ logging_config_func(DEFAULT_LOGGING)
- # ... then invoke it with the logging settings
- logging_config_func(self.LOGGING)
+ if self.LOGGING:
+ # Backwards-compatibility shim for #16288 fix
+ compat_patch_logging_config(self.LOGGING)
+
+ # ... then invoke it with the logging settings
+ logging_config_func(self.LOGGING)
def configure(self, default_settings=global_settings, **options):
"""
diff --git a/django/conf/global_settings.py b/django/conf/global_settings.py
index 708e9c9f70..f1cbb22880 100644
--- a/django/conf/global_settings.py
+++ b/django/conf/global_settings.py
@@ -551,33 +551,8 @@ MESSAGE_STORAGE = 'django.contrib.messages.storage.fallback.FallbackStorage'
# The callable to use to configure logging
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.RequireDebugFalse',
- }
- },
- 'handlers': {
- 'mail_admins': {
- 'level': 'ERROR',
- 'filters': ['require_debug_false'],
- 'class': 'django.utils.log.AdminEmailHandler'
- }
- },
- 'loggers': {
- 'django.request': {
- 'handlers': ['mail_admins'],
- 'level': 'ERROR',
- 'propagate': True,
- },
- }
-}
+# Custom logging configuration.
+LOGGING = {}
# Default exception reporter filter class used in case none has been
# specifically assigned to the HttpRequest instance.
diff --git a/django/utils/log.py b/django/utils/log.py
index df2089f924..c111512fe8 100644
--- a/django/utils/log.py
+++ b/django/utils/log.py
@@ -5,6 +5,7 @@ from django.conf import settings
from django.core import mail
from django.views.debug import ExceptionReporter, get_exception_reporter_filter
+
# Make sure a NullHandler is available
# This was added in Python 2.7/3.2
try:
@@ -23,12 +24,38 @@ except ImportError:
getLogger = logging.getLogger
-# Ensure the creation of the Django logger
-# with a null handler. This ensures we don't get any
-# 'No handlers could be found for logger "django"' messages
-logger = getLogger('django')
-if not logger.handlers:
- logger.addHandler(NullHandler())
+# 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 = {
+ 'version': 1,
+ 'disable_existing_loggers': False,
+ 'filters': {
+ 'require_debug_false': {
+ '()': 'django.utils.log.RequireDebugFalse',
+ }
+ },
+ 'handlers': {
+ 'null': {
+ 'class': 'django.utils.log.NullHandler',
+ },
+ 'mail_admins': {
+ 'level': 'ERROR',
+ 'filters': ['require_debug_false'],
+ 'class': 'django.utils.log.AdminEmailHandler'
+ }
+ },
+ 'loggers': {
+ 'django': {
+ 'handlers': ['null'],
+ },
+ 'django.request': {
+ 'handlers': ['mail_admins'],
+ 'level': 'ERROR',
+ 'propagate': True,
+ },
+ }
+}
class AdminEmailHandler(logging.Handler):