The Logger.debug example (at <a href="http://docs.python.org/py3k/library/logging.html#logging.Logger.debug">http://docs.python.org/py3k/library/logging.html#logging.Logger.debug</a>) does not actually work in Python 3.2:<br>

<br>Python 3.2 (r32:88452, Feb 20 2011, 11:12:31) <br>[GCC 4.2.1 (Apple Inc. build 5664)] on darwin<br>Type &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information.<br>&gt;&gt;&gt; import logging<br>

&gt;&gt;&gt; FORMAT = &#39;%(asctime)-15s %(clientip)s %(user)-8s %(message)s&#39;<br>&gt;&gt;&gt; logging.basicConfig(format=FORMAT)<br>&gt;&gt;&gt; d = {&#39;clientip&#39;: &#39;192.168.0.1&#39;, &#39;user&#39;: &#39;fbloggs&#39;}<br>

&gt;&gt;&gt; logging.warning(&#39;Protocol problem: %s&#39;, &#39;connection reset&#39;, extra=d)<br>Traceback (most recent call last):<br>  File &quot;/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/logging/__init__.py&quot;, line 934, in emit<br>

    msg = self.format(record)<br>  File &quot;/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/logging/__init__.py&quot;, line 809, in format<br>    return fmt.format(record)<br>  File &quot;/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/logging/__init__.py&quot;, line 551, in format<br>

    s = self.formatMessage(record)<br>  File &quot;/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/logging/__init__.py&quot;, line 520, in formatMessage<br>    return self._style.format(record)<br>  File &quot;/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/logging/__init__.py&quot;, line 371, in format<br>

    return self._fmt % record.__dict__<br>KeyError: &#39;asctime&#39;<br>Logged from file &lt;stdin&gt;, line 1<br><br>The problem is that the logger expects to see the exact string &quot;%(asctime)s&quot; in the format string before it will add the asctime attribute. Using the &quot;-15&quot; modifier on the asctime causes the match to fail, and the asctime attribute is not emitted. To fix the example, change %(asctime)-15s to %(asctime)s:<br>

<br>Python 3.2 (r32:88452, Feb 20 2011, 11:12:31) <br>[GCC 4.2.1 (Apple Inc. build 5664)] on darwin<br>Type &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information.<br>&gt;&gt;&gt; import logging<br>

&gt;&gt;&gt; FORMAT = &#39;%(asctime)s %(clientip)s %(user)-8s %(message)s&#39;<br>&gt;&gt;&gt; logging.basicConfig(format=FORMAT)<br>&gt;&gt;&gt; d = { &#39;clientip&#39; : &#39;192.168.0.1&#39;, &#39;user&#39; : &#39;fbloggs&#39; }<br>

&gt;&gt;&gt; logger = logging.getLogger(&#39;tcpserver&#39;)<br>&gt;&gt;&gt; logger.warning(&#39;Protocol problem: %s&#39;, &#39;connection reset&#39;, extra=d)<br>2011-07-12 13:39:44,317 192.168.0.1 fbloggs  Protocol problem: connection reset<br>

<br>This also reflects a problem in the library in that it is not flexible enough to understand different formats. As a separate matter, perhaps the library could be amended to always include the asctime field (the asctime string could be lazily computed by using a class instance for which the __str__ method produces the actual formatted date), rather than trying to guess when it is needed.<br>

<br>Robert<br>