By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,930 Members | 1,492 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,930 IT Pros & Developers. It's quick & easy.

logging module's documentation lies?

P: n/a
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
Jun 27 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On Jun 24, 2:35*pm, "ludvig.eric...@gmail.com"
<ludvig.eric...@gmail.comwrote:
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
Jun 27 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.