Closed as not planned
Closed as not planned
Copy link
Description
Bug report
Checklist
- I am confident this is a bug in CPython,
not a bug in a third-party project - I have searched the CPython issue tracker,
and am confident this bug has not been reported before
A clear and concise description of the bug
After using basicConfig
or dictConfig
for a logger, handlers
attribute would still be []
while hasHandlers
equals True
. Even though handlers
is empty, StreamHandler still works and prints out log messages.
Code:
import logging
import logging.config
basic_logger = logging.getLogger("basic")
print(f"hasHandlers: {basic_logger.hasHandlers()}, handlers: {basic_logger.handlers}")
basic_logger.error("1")
logging.basicConfig(level=logging.INFO)
print(f"hasHandlers: {basic_logger.hasHandlers()}, handlers: {basic_logger.handlers}")
basic_logger.error("2")
config = {
"version": 1.0,
"handlers": {
"console": {
"class": "logging.StreamHandler",
"level": "DEBUG",
"stream": "ext://sys.stdout"
}
},
"root": {
"level": "DEBUG",
"handlers": ["console"]
}
}
logging.config.dictConfig(config)
dict_logger = logging.getLogger("dict")
print(f"hasHandlers: {dict_logger.hasHandlers()}, handlers: {dict_logger.handlers}")
dict_logger.error("3")
Output:
hasHandlers: False, handlers: []
hasHandlers: True, handlers: []
hasHandlers: True, handlers: []
3
1
ERROR:basic:2
Your environment
- CPython versions tested on: Python 3.9.16
- Operating system and architecture: MacOS Monterey 12.6.1
Metadata
Metadata
Assignees
Labels
Projects
Status
Done