X Tutup
The Wayback Machine - https://web.archive.org/web/20251215055039/https://github.com/python/cpython/issues/103008
Skip to content

[logging] parsing dictConfig for formatters: key name "format" does not correspond to constructor parameter name "fmt" #103008

@Xezarior

Description

@Xezarior

Bug report

Creating a new formatter in a dictConfig requires the format string to be specified with the key "format" instead of "fmt".
This is inconsistent with the syntax for the class constructor.

Furthermore, the result is that the resulting formatter quietly drops the specified format string replacing it with {message} for no apparent reason.

While the documentation states "format" as key name, all other keys are identically named to the constructor and this causes an unnecessary risk for confusion and errors. Especially since "fmt" and "format" do read very similarly.

I believe it would be a good addition to allow the key "fmt" to be read equivalently to "format" since this may be unwanted behaviour.

MWE:

import logging
config = {
    "version": 1,
    "formatters": {
        "default": { "fmt": "%(levelname)s %(message)s" }
    },
    "handlers": {
        "console": {
            "class": "logging.StreamHandler",
            "formatter": "default"
        }
    },
    "loggers": {
        "log": { "handlers": ["console"] }
    }
}
logging.config.dictConfig(config)
logging.info("test")

Causes the log record to drop the levelname.

Your environment

Python 3.11.2 (tags/v3.11.2:878ead1, Feb 7 2023, 16:38:35) [MSC v.1934 64 bit (AMD64)] on win32
Windows 11 64 bit

P.S.: This is my first bug report in a project of such size, please kindly help me improving if needed.
EDIT: added link to documentation of Dictionary Schema Details.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directory

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      X Tutup