Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Attribute handlers is empty after using basicConfig or dictConfig #107515

Copy link
Copy link
Closed as not planned
@hundredball

Description

@hundredball
Issue body actions

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

invalidstdlibPython modules in the Lib dirPython modules in the Lib dir

Projects

Status

Done
Show more project fields

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.