Python日志配置
import logging
from logging.handlers import RotatingFileHandler
log = logging.getLogger()
log.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s %(levelname)s: %(filename)s:%(lineno)d %(message)s')
# 输出到文件
file_log_handler = RotatingFileHandler("log_debug.log", maxBytes=1024 * 1024 * 100, backupCount=10)
file_log_handler.setFormatter(formatter)
log.addHandler(file_log_handler)
# 输出到控制台
stream_log_handler = logging.StreamHandler()
stream_log_handler.setFormatter(formatter)
log.addHandler(stream_log_handler)
logging.debug("aaa")
logging.info("bbb")
logging.warning("ccc")