很多程式都有記錄日志的需求,并且日志中包含的資訊即有正常的程式通路日志,還可能有錯誤、警告等資訊輸出,python的logging子產品提供了标準的日志接口,你可以通過它存儲各種格式的日志,logging的日志可以分為 <code>debug()</code>, <code>info()</code>, <code>warning()</code>, <code>error()</code> and <code>critical() 5個級别</code>
<code></code>
Level
When it’s used
<code>DEBUG</code>
Detailed information, typically of interest only when diagnosing problems.
<code>INFO</code>
Confirmation that things are working as expected.
<code>WARNING</code>
An indication that something unexpected happened, or indicative of some problem in the near future (e.g. ‘disk space low’). The software is still working as expected.
<code>ERROR</code>
Due to a more serious problem, the software has not been able to perform some function.
<code>CRITICAL</code>
A serious error, indicating that the program itself may be unable to continue running.
日志格式:<code></code>
%(name)s
Logger的名字
%(levelno)s
數字形式的日志級别
%(levelname)s
文本形式的日志級别
%(pathname)s
調用日志輸出函數的子產品的完整路徑名,可能沒有
%(filename)s
調用日志輸出函數的子產品的檔案名
%(module)s
調用日志輸出函數的子產品名
%(funcName)s
調用日志輸出函數的函數名
%(lineno)d
調用日志輸出函數的語句所在的代碼行
%(created)f
目前時間,用UNIX标準的表示時間的浮 點數表示
%(relativeCreated)d
輸出日志資訊時的,自Logger建立以 來的毫秒數
%(asctime)s
字元串形式的目前時間。預設格式是 “2003-07-08 16:49:45,896”。逗号後面的是毫秒
%(thread)d
線程ID。可能沒有
%(threadName)s
線程名。可能沒有
%(process)d
程序ID。可能沒有
%(message)s
使用者輸出的消息
本文轉自 奚落123 51CTO部落格,原文連結:http://blog.51cto.com/guyuyuan/1926572,如需轉載請自行聯系原作者