Posted in Python onSeptember 29, 2014
本文实例讲述了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程序设计有所帮助。
Python中logging模块的用法实例
- Author -
shichen2014声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Reply on: @reply_date@
@reply_contents@