summaryrefslogtreecommitdiff
path: root/tests/logging_tests/tests.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/logging_tests/tests.py')
-rw-r--r--tests/logging_tests/tests.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/tests/logging_tests/tests.py b/tests/logging_tests/tests.py
index a4de7424f8..9690147e81 100644
--- a/tests/logging_tests/tests.py
+++ b/tests/logging_tests/tests.py
@@ -573,6 +573,10 @@ class SetupConfigureLogging(SimpleTestCase):
Calling django.setup() initializes the logging configuration.
"""
+ def tearDown(self):
+ super().tearDown()
+ dictConfig.called = False
+
def test_configure_initializes_logging(self):
from django import setup
@@ -586,6 +590,44 @@ class SetupConfigureLogging(SimpleTestCase):
setup()
self.assertTrue(dictConfig.called)
+ def test_logging_settings_changed(self):
+ """
+ Logging is reconfigured when LOGGING or LOGGING_CONFIG changes.
+ """
+ new_logging_info = {
+ "version": 1,
+ "disable_existing_loggers": False,
+ "loggers": {
+ "django.test_custom_logger": {
+ "level": "INFO",
+ }
+ },
+ }
+ new_logging_warning = {
+ "version": 1,
+ "disable_existing_loggers": False,
+ "loggers": {
+ "django.test_custom_logger": {
+ "level": "WARNING",
+ }
+ },
+ }
+ logger = logging.getLogger("django.test_custom_logger")
+
+ with override_settings(LOGGING=new_logging_info):
+ self.assertEqual(logger.level, logging.INFO)
+
+ # Repeating the operation works.
+ with override_settings(LOGGING=new_logging_warning):
+ self.assertEqual(logger.level, logging.WARNING)
+
+ # The default unconfigured level is NOTSET.
+ self.assertEqual(logger.level, logging.NOTSET)
+
+ self.assertIs(dictConfig.called, False)
+ with override_settings(LOGGING_CONFIG="logging_tests.tests.dictConfig"):
+ self.assertIs(dictConfig.called, True)
+
@override_settings(DEBUG=True, ROOT_URLCONF="logging_tests.urls")
class SecurityLoggerTest(LoggingAssertionMixin, SimpleTestCase):