欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Python logging管理不同級(jí)別log打印和存儲(chǔ)實(shí)例

 更新時(shí)間:2018年01月19日 11:16:03   作者:Hank_Gao  
這篇文章主要介紹了Python logging管理不同級(jí)別log打印和存儲(chǔ)實(shí)例,具有一定借鑒價(jià)值,需要的朋友可以參考下

Python內(nèi)置模塊logging管理不同級(jí)別log打印和存儲(chǔ),非常方便,從此告別了使用print打樁記錄,我們來(lái)看下logging的魅力吧

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 = './logcheck.log', 
          filemode = 'w') 
 
############################################################################### 
#define one StreamHandler, set the log mode 
console = logging.StreamHandler() 
console.setLevel(logging.INFO) 
formatter = logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s') 
console.setFormatter(formatter) 
logging.getLogger('').addHandler(console) 
############################################################################### 
 
filePath = r'C:\ddms.bat' 
 
logging.error('Open file failed!') 
logging.warn('sort mode disabled') 
logging.debug('%s' % filePath) 
logging.info('xml file generated successfully!') 

運(yùn)行結(jié)果:

root    : ERROR  Open file failed! 
root    : WARNING sort mode disabled 
root    : INFO   xml file generated successfully! 

總結(jié)

以上就是本文關(guān)于Python logging管理不同級(jí)別log打印和存儲(chǔ)實(shí)例的全部?jī)?nèi)容,希望對(duì)大家有所幫助。感興趣的朋友可以繼續(xù)參閱本站其他相關(guān)專題,如有不足之處,歡迎留言指出。感謝朋友們對(duì)本站的支持!

相關(guān)文章

最新評(píng)論