日志处理logger
生活随笔
收集整理的這篇文章主要介紹了
日志处理logger
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
20220127
https://mp.weixin.qq.com/s/CgmfVqogqKBzezmIR7ZfsQ
https://blog.csdn.net/kyle1314608/article/details/122714312
錯誤日志輸出重點
20220126
https://blog.csdn.net/weixin_45365220/article/details/109270375
添加日志
import logging
type='數值字段識別測試'
def log(type):#創建logger,如果參數為空則返回root loggerlogger = logging.getLogger("wsy")logger.setLevel(logging.DEBUG) #設置logger日志等級#這里進行判斷,如果logger.handlers列表為空,則添加,否則,直接去寫日志if not logger.handlers:#創建handlerfh = logging.FileHandler(str(time)+str(type),encoding="utf-8")ch = logging.StreamHandler()#設置輸出日志格式formatter = logging.Formatter(fmt="%(asctime)s %(name)s %(filename)s %(message)s",datefmt="%Y/%m/%d %X")#為handler指定輸出格式fh.setFormatter(formatter)ch.setFormatter(formatter)#為logger添加的日志處理器logger.addHandler(fh)logger.addHandler(ch)return logger #直接返回loggerlogger = log(type)logger.debug('xxx'.format)
總結
以上是生活随笔為你收集整理的日志处理logger的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: dataframe sample 采样,
- 下一篇: python压缩和解压缩