日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > python >内容正文

python

python三十九:logging模块

發(fā)布時間:2025/6/15 python 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python三十九:logging模块 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
import logginglogging.basicConfig(level=logging.DEBUG # 設(shè)置日志級別, 默認(rèn)為 WARNING,filename="logger.log" # 將日志信息輸出到文件中,filemode="w" # 文件打開模式,默認(rèn)為'a'# asctime:字符串形式的當(dāng)前時間 filename:文件名稱 lineno日志的行號 message:日志信息,format="%(asctime)s %(filename)s [%(lineno)d] %(message)s" # 日志顯示格式 )logging.debug("debug message") logging.info("info message") # 默認(rèn)情況下, python的logging模塊將日志打印到了標(biāo)準(zhǔn)輸出中, # 且只顯示了大于等于WARNING級別的日志 logging.warning("warning message") logging.error("error message") logging.critical("critical message") #---------------------- logger對象 logger = logging.getLogger()fh = logging.FileHandler("loger.txt") ch = logging.StreamHandler()fm = logging.Formatter("%(asctime)s %(message)s") # 日志格式 fh.setFormatter(fm) ch.setFormatter(fm)logger.addHandler(fh) logger.addHandler(ch) logger.setLevel("DEBUG")logger.debug("debug message") logger.info("info message") logger.warning("warning message") logger.error("error message") logger.critical("critical message")

?

import logging logger = logging.getLogger() # root的logger # 名字相同的logger是同一個logger對象 logger1 = logging.getLogger("myLogger") # logger可以起名字,一切l(wèi)ogger都是root的"兒子"ch = logging.StreamHandler()logger.addHandler(ch) logger1.addHandler(ch)logger1.setLevel("DEBUG")logger.debug("logger debug message") logger.info("logger info message") logger.warning("logger warning message") logger.error("logger error message") logger.critical("logger critical message")logger1.debug("logger1 debug message") logger1.info("logger1 info message") logger1.warning("logger1 warning message") logger1.error("logger1 error message") logger1.critical("logger1 critical message")

?

總結(jié)

以上是生活随笔為你收集整理的python三十九:logging模块的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。