logging module's documentation lies?

L

ludvig.ericson

Quote from the docs:

FORMAT = "%(asctime)-15s %(clientip)s %(user)-8s %(message)s"
logging.basicConfig(format=FORMAT)
d = {'clientip': '192.168.0.1', 'user': 'fbloggs'}
logging.warning("Protocol problem: %s", "connection reset",
extra=d)

would print something like

2006-02-08 22:20:02,165 192.168.0.1 fbloggs Protocol problem:
connection reset

If we try to run that exact example, which doesn't seem logically
flawed in any way:
extra=d)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.5/site-packages/logging/__init__.py",
line 1266, in warning
apply(root.warning, (msg,)+args, kwargs)
File "/usr/lib/python2.5/site-packages/logging/__init__.py",
line 969, in warning
apply(self._log, (WARNING, msg, args), kwargs)
TypeError: _log() got an unexpected keyword argument 'extra'

I tried using **d instead, no show. I tried extra=d in Python 2.4, no
show. I tried **d in Python 2.4, no show.

So, my question unto the lot of you is: Do the docs for the logging
module lie to me?

URL: http://docs.python.org/lib/module-logging.html
 
M

Matimus

Quote from the docs:

    FORMAT = "%(asctime)-15s %(clientip)s %(user)-8s %(message)s"
    logging.basicConfig(format=FORMAT)
    d = {'clientip': '192.168.0.1', 'user': 'fbloggs'}
    logging.warning("Protocol problem: %s", "connection reset",
extra=d)

would print something like

    2006-02-08 22:20:02,165 192.168.0.1 fbloggs  Protocol problem:
connection reset

If we try to run that exact example, which doesn't seem logically
flawed in any way:

    >>> import logging
    >>> FORMAT = "%(asctime)-15s %(clientip)s %(user)-8s %(message)s"
    >>> logging.basicConfig(format=FORMAT)
    >>> d = {'clientip': '192.168.0.1', 'user': 'fbloggs'}
    >>> logging.warning("Protocol problem: %s", "connection reset",
extra=d)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/usr/lib/python2.5/site-packages/logging/__init__.py",
line 1266, in warning
        apply(root.warning, (msg,)+args, kwargs)
      File "/usr/lib/python2.5/site-packages/logging/__init__.py",
line 969, in warning
        apply(self._log, (WARNING, msg, args), kwargs)
    TypeError: _log() got an unexpected keyword argument 'extra'

I tried using **d instead, no show. I tried extra=d in Python 2.4, no
show. I tried **d in Python 2.4, no show.

So, my question unto the lot of you is: Do the docs for the logging
module lie to me?

URL:http://docs.python.org/lib/module-logging.html

From the documentation: `Changed in version 2.5: extra was added.`

Documentation never lies, authors do. Or, in this case, don't.

Matt
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,118
Latest member
LatishaWhy
Top