summaryrefslogtreecommitdiff
path: root/django/utils/log.py
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2013-12-31 12:28:01 +0100
committerClaude Paroz <claude@2xlibre.net>2013-12-31 18:35:00 +0100
commitb8e3373f458aa363d59c61b58be390a5a1156467 (patch)
treee2805d1eff7056999c5cf46b6c4c088fbae8d790 /django/utils/log.py
parent1d23d766ab85301eb527629400933fd601355f1a (diff)
Fixed #21714 -- Moved logging configuration to global setup()
Thanks Aymeric Augustin for the report and the review.
Diffstat (limited to 'django/utils/log.py')
-rw-r--r--django/utils/log.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/django/utils/log.py b/django/utils/log.py
index 488632882c..cf778b619b 100644
--- a/django/utils/log.py
+++ b/django/utils/log.py
@@ -1,8 +1,11 @@
import logging
+import sys
+import warnings
from django.conf import settings
from django.core import mail
from django.core.mail import get_connection
+from django.utils.module_loading import import_by_path
from django.views.debug import ExceptionReporter, get_exception_reporter_filter
# Imports kept for backwards-compatibility in Django 1.7.
@@ -61,6 +64,24 @@ DEFAULT_LOGGING = {
}
+def configure_logging(logging_config, logging_settings):
+ if not sys.warnoptions:
+ # Route warnings through python logging
+ logging.captureWarnings(True)
+ # Allow DeprecationWarnings through the warnings filters
+ warnings.simplefilter("default", DeprecationWarning)
+
+ if logging_config:
+ # First find the logging configuration function ...
+ logging_config_func = import_by_path(logging_config)
+
+ logging_config_func(DEFAULT_LOGGING)
+
+ # ... then invoke it with the logging settings
+ if logging_settings:
+ logging_config_func(logging_settings)
+
+
class AdminEmailHandler(logging.Handler):
"""An exception log handler that emails log entries to site admins.