Bug report
Bug description:
Invoking logging.config.dictConfig() with "disable_existing_loggers": False breaks already added handlers, even if the config is empty. Specifically, it calls flush() and close() of all existing handlers.
Test script:
import logging
import logging.config
# test setup: add a FileHandler as the only handler of the root logger
fileHandler = logging.FileHandler("./debug_log.txt", mode="w")
fileHandler.setFormatter(logging.Formatter("%(message)s"))
root_logger = logging.getLogger()
root_logger.addHandler(fileHandler)
# this works fine - the message is added to the file
logging.warning("test message 1")
# set a trivial configuration: no formatters, handlers or loggers.
# "disable_existing_loggers" is set to False
logging.config.dictConfig({"version": 1, "disable_existing_loggers": False})
# the FileHandler doesn't work anymore - this message won't be added to the file
logging.warning("test message 2")
# the handler is in inconsistent state - it's still added to the logger,
# but it's already flush()'ed and close()'d
assert fileHandler in root_logger.handlers
assert fileHandler._closed == True
The content of the debug_log.txt after running this script is the following:
But it supposed to be
test message 1
test message 2
Maybe issue #123239 is somehow related.
CPython versions tested on:
3.13
Operating systems tested on:
macOS
Linked PRs
Bug report
Bug description:
Invoking
logging.config.dictConfig()with"disable_existing_loggers": Falsebreaks already added handlers, even if the config is empty. Specifically, it callsflush()andclose()of all existing handlers.Test script:
The content of the
debug_log.txtafter running this script is the following:But it supposed to be
Maybe issue #123239 is somehow related.
CPython versions tested on:
3.13
Operating systems tested on:
macOS
Linked PRs