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:
@@ -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 ...
|
||||
|
||||
@@ -62,6 +62,9 @@ DEFAULT_LOGGING = {
|
||||
'level': 'ERROR',
|
||||
'propagate': False,
|
||||
},
|
||||
'py.warnings': {
|
||||
'handlers': ['console'],
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user