-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
Closed as not planned
Closed as not planned
Copy link
Labels
pendingThe issue will be closed if no feedback is providedThe issue will be closed if no feedback is providedstdlibPython modules in the Lib dirPython modules in the Lib dir
Description
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:
test message 1
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
mirko0x5f
Metadata
Metadata
Assignees
Labels
pendingThe issue will be closed if no feedback is providedThe issue will be closed if no feedback is providedstdlibPython modules in the Lib dirPython modules in the Lib dir
Projects
Status
Done