summaryrefslogtreecommitdiff
path: root/Lib/logging
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2018-07-02 02:35:09 -0700
committerVinay Sajip <vinay_sajip@yahoo.co.uk>2018-07-02 10:35:09 +0100
commit6f49afc3d983350f4f04d221a26573721f23c475 (patch)
tree2eae2dadcb17735ff99ee8c8dc7bb2847f2e2a51 /Lib/logging
parentf9ae07441cba52e680356a42972c92fd86e9adf4 (diff)
downloadcpython-git-6f49afc3d983350f4f04d221a26573721f23c475.tar.gz
bpo-33978: Close existing handlers before logging (re-)configuration. (GH-8008) (GH-8044)
(cherry picked from commit 087570af6d5d39b51bdd5e660a53903960e58678) Co-authored-by: Xtreak <tirkarthi@users.noreply.github.com>
Diffstat (limited to 'Lib/logging')
-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)