mirror of
https://github.com/python/cpython.git
synced 2025-10-10 00:43:41 +00:00
bpo-33978: Close existing handlers before logging (re-)configuration. (GH-8008)
This commit is contained in:
parent
c6cd164cff
commit
087570af6d
3 changed files with 88 additions and 4 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue