logging module's documentation lies?

Matimus mccredie at gmail.com
Tue Jun 24 18:50:54 EDT 2008


On Jun 24, 2:35 pm, "ludvig.eric... at gmail.com"
<ludvig.eric... at gmail.com> wrote:
> 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



More information about the Python-list mailing list