python-logging模块下的logger函数

import logging
logger=logging.getLogger()

fh=logging.FileHandler('text.log')
ch=logging.StreamHandler()

fm=logging.Formatter("%(asctime)s %(message)s")
fh.setFormatter(fm)
ch.setFormatter(fm)

logger.addHandler(fh)
logger.addHandler(ch)
logger.setLevel("ERROR")

logger.debug("a")
logger.info("b")
logger.warning("c")
logger.error("d")
logger.critical("e")

猜你喜欢

转载自www.cnblogs.com/benchdog/p/9094302.html