1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

Fixed #18985 -- made DeprecationWarnings loud

Capture warnings in Python >= 2.7 and route through
console handler, which is subject to DEBUG==True

Thanks to dstufft for the idea, and claudep for initial patch
This commit is contained in:
Preston Holmes
2012-11-16 16:50:50 -08:00
parent b4a98e028a
commit 44046e8a38
4 changed files with 49 additions and 0 deletions

View File

@@ -6,6 +6,7 @@ variable, and then from django.conf.global_settings; see the global settings fil
a list of all possible variables.
"""
import logging
import os
import time # Needed for Windows
import warnings
@@ -55,6 +56,15 @@ class LazySettings(LazyObject):
"""
Setup logging from LOGGING_CONFIG and LOGGING settings.
"""
try:
# Route warnings through python logging
logging.captureWarnings(True)
# Allow DeprecationWarnings through the warnings filters
warnings.simplefilter("default", DeprecationWarning)
except AttributeError:
# No captureWarnings on Python 2.6, DeprecationWarnings are on anyway
pass
if self.LOGGING_CONFIG:
from django.utils.log import DEFAULT_LOGGING
# First find the logging configuration function ...

View File

@@ -62,6 +62,9 @@ DEFAULT_LOGGING = {
'level': 'ERROR',
'propagate': False,
},
'py.warnings': {
'handlers': ['console'],
},
}
}