logging module's documentation lies?

ludvig.ericson at gmail.com ludvig.ericson at gmail.com
Tue Jun 24 17:35:38 EDT 2008


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



More information about the Python-list mailing list