summaryrefslogtreecommitdiff
path: root/Lib/logging/config.py
diff options
context:
space:
mode:
authorXtreak <tirkarthi@users.noreply.github.com>2018-07-02 14:27:46 +0530
committerVinay Sajip <vinay_sajip@yahoo.co.uk>2018-07-02 09:57:46 +0100
commit087570af6d5d39b51bdd5e660a53903960e58678 (patch)
tree44556f42bbe02071a5a6f4f51781762b174ace32 /Lib/logging/config.py
parentc6cd164cffedb306a4c6644d9d03072f24da246d (diff)
downloadcpython-git-087570af6d5d39b51bdd5e660a53903960e58678.tar.gz
bpo-33978: Close existing handlers before logging (re-)configuration. (GH-8008)
Diffstat (limited to 'Lib/logging/config.py')
-rw-r--r--Lib/logging/config.py15
1 files changed, 11 insertions, 4 deletions
diff --git a/Lib/logging/config.py b/Lib/logging/config.py
index 1b0facaf62..fa1a398aee 100644
--- a/Lib/logging/config.py
+++ b/Lib/logging/config.py
@@ -73,8 +73,8 @@ def fileConfig(fname, defaults=None, disable_existing_loggers=True):
# critical section
logging._acquireLock()
try:
- logging._handlers.clear()
- del logging._handlerList[:]
+ _clearExistingHandlers()
+
# Handlers add themselves to logging._handlers
handlers = _install_handlers(cp, formatters)
_install_loggers(cp, handlers, disable_existing_loggers)
@@ -265,6 +265,14 @@ def _install_loggers(cp, handlers, disable_existing):
# logger.disabled = 1
_handle_existing_loggers(existing, child_loggers, disable_existing)
+
+def _clearExistingHandlers():
+ """Clear and close existing handlers"""
+ logging._handlers.clear()
+ logging.shutdown(logging._handlerList[:])
+ del logging._handlerList[:]
+
+
IDENTIFIER = re.compile('^[a-z_][a-z0-9_]*$', re.I)
@@ -524,8 +532,7 @@ class DictConfigurator(BaseConfigurator):
else:
disable_existing = config.pop('disable_existing_loggers', True)
- logging._handlers.clear()
- del logging._handlerList[:]
+ _clearExistingHandlers()
# Do formatters first - they don't refer to anything else
formatters = config.get('formatters', EMPTY_DICT)