Skip to content

logging.LogRecord should know how to handle dict-like args #46725

Closed

Description

@wcmaier
mannequin
BPO 2473
Nosy @vsajip

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = 'https://github.com/vsajip'
closed_at = <Date 2008-03-29.20:14:26.106>
created_at = <Date 2008-03-24.13:56:05.847>
labels = ['invalid', 'type-feature', 'library']
title = 'logging.LogRecord should know how to handle dict-like args'
updated_at = <Date 2008-03-29.20:14:26.098>
user = 'https://bugs.python.org/wcmaier'

bugs.python.org fields:

activity = <Date 2008-03-29.20:14:26.098>
actor = 'vinay.sajip'
assignee = 'vinay.sajip'
closed = True
closed_date = <Date 2008-03-29.20:14:26.106>
closer = 'vinay.sajip'
components = ['Library (Lib)']
creation = <Date 2008-03-24.13:56:05.847>
creator = 'wcmaier'
dependencies = []
files = []
hgrepos = []
issue_num = 2473
keywords = []
message_count = 2.0
messages = ['64415', '64723']
nosy_count = 2.0
nosy_names = ['vinay.sajip', 'wcmaier']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = None
status = 'closed'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue2473'
versions = ['Python 2.5']

Activity

  1. wcmaier commented on Mar 24, 2008

    wcmaiermannequin
    MannequinAuthor

    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:

    logging.__init__.py:204..238
    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]) ==
    types.DictType):
    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.

    Thanks!

  2. added
    stdlibStandard Library Python modules in the Lib/ directory
    type-featureA feature request or enhancement
    on Mar 24, 2008
  3. vsajip commented on Mar 29, 2008

    @vsajip
    Member

    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:

    dict(userDict_or_mixIn_instance)

    and pass that into the logging call instead of userDict_or_mixIn_instance.

  4. self-assigned this
    on Mar 29, 2008
  5. transferred this issue fromon Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

stdlibStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancement

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions