擅长:python、mysql、java
<p>默认格式位于<a href="http://hg.python.org/cpython/file/5c4ca109af1c/Lib/logging/__init__.py#l1640" rel="noreferrer">here</a>,即:</p>
<pre class="lang-py prettyprint-override"><code>BASIC_FORMAT = "%(levelname)s:%(name)s:%(message)s"
</code></pre>
<p><a href="http://hg.python.org/cpython/file/5c4ca109af1c/Lib/logging/__init__.py#l399" rel="noreferrer">Format</a>代码将告诉您如何自定义它。下面是一个关于如何自定义它的示例。</p>
<pre class="lang-py prettyprint-override"><code>import sys
import logging
logging.basicConfig(
level=logging.DEBUG,
format="[%(asctime)s] %(levelname)s [%(name)s.%(funcName)s:%(lineno)d] %(message)s",
datefmt="%H:%M:%S",
stream=sys.stdout)
logging.info("HEY")
</code></pre>
<p>结果是:</p>
<pre class="lang-none prettyprint-override"><code>[26/May/2013 06:41:40] INFO [root.<module>:1] HEY
</code></pre>