时间:2021-07-01 10:21:17 帮助过:33人阅读
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程序设计有所帮助。