python日誌等級 python 日誌輸出級別

2021-10-11 14:59:32 字數 980 閱讀 2121

import logging

logging.basicconfig(level=logging.debug,

format=』%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s』,

datefmt=』%a, %d %b %y %h:%m:%s』,

filename=』test.log』,

filemode=』w』)

#mode=w 為覆蓋,mode=a 為追加

logging.debug(『this is debug message』)

logging.info(『this is info message』)

logging.warning(『this is warning message』)

想關引數介紹:

logging.basicconfig函式各引數:

level總共分5個級別:debug < info< warning< error< critical

日誌資訊低於設定的級別時,不予顯示:如此處為最低級別debug,所以顯示所以資訊

filename: 指定日誌檔名

filemode: 和file函式意義相同,指定日誌檔案的開啟模式,』w』或』a』

format: 指定輸出的格式和內容,format可以輸出很多有用資訊。顯示的條目可以是以下內容:

%(levelname):日誌級別的名字格式

%(levelno)s:日誌級別的數字表示

%(name)s:日誌名字

%(funcname)s:函式名字

%(asctime):日誌時間,可以使用datefmt去定義時間格式,如上圖。

%(pathname):指令碼的絕對路徑

%(filename):指令碼的名字

%(module):模組的名字

%(thread):thread id

%(threadname):執行緒的名字

syslog日誌等級

設施.優先順序 facility.priority 設施 facility kern 0 核心日誌訊息 user 1 隨機的使用者日誌訊息 mail 2 郵件系統日誌訊息 daemon 3 系統守護程序日誌訊息 auth 4 安全管理日誌訊息 syslog 5 syslogd本身的日誌訊息 lpr ...

python 日誌模組 日誌等級設定失效的解決方案

問題 控制台和日誌的檔案的等級設定要放在 logger logging.getlogger myloger 例項化之後才會生效 不然就被logger預設的替代了 問題 當前日誌模組的等級設定 失效 現象 console level info handler level info handler fi...

程式設計日誌的等級劃分

在不同的版本中日誌的分級也有區別,下面以日誌記錄器logger的分類來進行討論 六個日誌等級 trace debug info warning error fatal 還有兩個特殊等級 all off,全部日誌開啟和關閉,這裡不做討論 info info 報告程式進度和狀態資訊。一般這種資訊都是一過...