This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: logging.LogRecord should know how to handle dict-like args
Type: enhancement Stage:
Components: Library (Lib) Versions: Python 2.5
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: vinay.sajip Nosy List: vinay.sajip, wcmaier
Priority: normal Keywords:

Created on 2008-03-24 13:56 by wcmaier, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (2)
msg64415 - (view) Author: Will Maier (wcmaier) Date: 2008-03-24 13:56
In (at least) Python 2.5.2, logging.logRecord provides a very useful
facility to interpolate formatted strings. This feature expands an *args
sequence; if that sequence has only one element and that element is a
dictionary, LogRecord uses the dictionary to interpolate keyword
formatted strings. This is incredibly useful, but the LogRecord
__init__() method includes a rather arbitrary type-specific check that
prevents users from passing dict-like objects to the log methods:
class LogRecord:
    def __init__(self, name, level, pathname, lineno,
                 msg, args, exc_info, func=None):
        if args and (len(args) == 1) and args[0] and (type(args[0]) ==
            args = args[0]

This restriction prevents the user from passing eg a subclass of
UserDict.DictMixin. Now, __init__() clearly does need to do _some_
checking of args, but it would be nice if that checking accepted
dict-like objects. I haven't come up with a good way to do this myself
yet, but I figured I'd submit the request now.

msg64723 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2008-03-29 20:14
You don't need to change the logging package for this. Simply generate a
bona-fide dict from your UserDict or DictMixin subclass as follows:


and pass that into the logging call instead of userDict_or_mixIn_instance.
Date User Action Args
2022-04-11 14:56:32adminsetgithub: 46725
2008-03-29 20:14:26vinay.sajipsetstatus: open -> closed
assignee: vinay.sajip
resolution: not a bug
messages: + msg64723
nosy: + vinay.sajip
2008-03-24 13:56:05wcmaiercreate