在logging中,Logger's level 的默認(rèn)等級(jí)為warning

所以雖然在handler中setlervel了,Logger's level 和Handler's Level 但是level取較高的那個(gè)(待校驗(yàn))
所以日志的level 為warning
解決此問題可以采用
logging.root.setLevel(logging.NOTSET)

完整源碼如下圖:
import logging
class loggerr(object):
def __init__(self,logger):
self.logger = logging.getLogger(logger)
self.fmt=logging.Formatter('%(asctime)s - %(name)s - %(levelname)s -%(message)s ')
logging.root.setLevel(logging.NOTSET)
#logging.basicConfig(level=logging.NOTSET)
def getlog(self):
ch=logging.StreamHandler()
sh=logging.FileHandler('log1.log')
ch.setFormatter(self.fmt)
sh.setFormatter(self.fmt)
ch.setLevel(logging.INFO)
sh.setLevel(logging.INFO)
self.logger.addHandler(ch)
self.logger.addHandler(sh)
return self.logger
if __name__ == '__main__':
mylog=loggerr('mylog').getlog()
mylog.info('infolog')
mylog.debug('debuglog')
mylog.warning('warninglog')
mylog.error('errorlog')
分享名稱:在python中l(wèi)oggersetlevel沒有生效的解決-創(chuàng)新互聯(lián)
文章位置:http://www.chinadenli.net/article22/dioccc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供靜態(tài)網(wǎng)站、外貿(mào)網(wǎng)站建設(shè)、網(wǎng)站內(nèi)鏈、營(yíng)銷型網(wǎng)站建設(shè)、App開發(fā)、微信小程序
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容