Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LogRecord attributes are not tuple, when logging only dict #69694

Closed
sejvlond mannequin opened this issue Oct 29, 2015 · 3 comments
Closed

LogRecord attributes are not tuple, when logging only dict #69694

sejvlond mannequin opened this issue Oct 29, 2015 · 3 comments

Comments

@sejvlond
Copy link
Mannequin

sejvlond mannequin commented Oct 29, 2015

BPO 25508
Nosy @vsajip, @bitdancer

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 = None
closed_at = <Date 2015-11-24.23:24:33.249>
created_at = <Date 2015-10-29.10:22:02.659>
labels = []
title = 'LogRecord attributes are not tuple, when logging only dict'
updated_at = <Date 2015-11-24.23:24:33.247>
user = 'https://bugs.python.org/sejvlond'

bugs.python.org fields:

activity = <Date 2015-11-24.23:24:33.247>
actor = 'python-dev'
assignee = 'none'
closed = True
closed_date = <Date 2015-11-24.23:24:33.249>
closer = 'python-dev'
components = []
creation = <Date 2015-10-29.10:22:02.659>
creator = 'sejvlond'
dependencies = []
files = []
hgrepos = []
issue_num = 25508
keywords = []
message_count = 3.0
messages = ['253673', '253676', '255303']
nosy_count = 4.0
nosy_names = ['vinay.sajip', 'r.david.murray', 'python-dev', 'sejvlond']
pr_nums = []
priority = 'normal'
resolution = 'fixed'
stage = 'resolved'
status = 'closed'
superseder = None
type = None
url = 'https://bugs.python.org/issue25508'
versions = ['Python 2.7', 'Python 3.4']

@sejvlond
Copy link
Mannequin Author

sejvlond mannequin commented Oct 29, 2015

Hi,

in doc https://docs.python.org/3.4/library/logging.html#logrecord-attributes there is
args You shouldn’t need to format this yourself. The tuple of arguments merged into msg to produce message.

But when I log message with 1 arg - a dict - in record.args will be this dict

import logging

class H(logging.Handler):
    def emit(self, record):
        print(record.args, type(record.args))

lgr = logging.getLogger()
lgr.addHandler(H())
lgr.error("msg", 1)
lgr.error("msg", dict(a=1))
lgr.error("msg", dict(a=1), 2)

output:

(1,) <class 'tuple'>
{'a': 1} <class 'dict'>
({'a': 1}, 2) <class 'tuple'>

@bitdancer
Copy link
Member

I believe this is due to the way % formatting works, and so is a doc bug. Vinay will know for sure, of course :)

@python-dev
Copy link
Mannequin

python-dev mannequin commented Nov 24, 2015

New changeset a365fb0dd5e1 by Vinay Sajip in branch '2.7':
Issue bpo-25508: Clarify documentation on LogRecord args attribute.
https://hg.python.org/cpython/rev/a365fb0dd5e1

New changeset 01998efb605a by Vinay Sajip in branch '3.4':
Issue bpo-25508: Clarify documentation on LogRecord args attribute.
https://hg.python.org/cpython/rev/01998efb605a

New changeset ca512b568368 by Vinay Sajip in branch '3.5':
Issue bpo-25508: Merged documentation fix from 3.4.
https://hg.python.org/cpython/rev/ca512b568368

New changeset 1da622f4630b by Vinay Sajip in branch 'default':
Closes bpo-25508: Merged documentation fix from 3.5.
https://hg.python.org/cpython/rev/1da622f4630b

@python-dev python-dev mannequin closed this as completed Nov 24, 2015
@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant