本文实例讲述了logging模块的用法实例,分享给大家供大家参考。具体方法如下:
import logging
import os
log = logging.getLogger()
formatter = logging.Formatter('[%(asctime)s] [%(name)s] %(levelname)s: %(message)s')
stream_handler = logging.StreamHandler()
file_handler = logging.FileHandler(os.path.join("c:\\", "analysis.log"))
file_handler.setFormatter(formatter)
stream_handler.setFormatter(formatter)
log.addHandler(file_handler)
log.addHandler(stream_handler)
log.setLevel(logging.DEBUG)
log.warn("a warning %s " % "c:\\")
程序运行结果如下:
[2014-09-29 10:23:58,905] [root] WARNING: a warning c:\
希望本文所述对大家的Python程序设计有所帮助。
Copyright© 2013-2020
All Rights Reserved 京ICP备2023019179号-8