LOG_FORMAT ="%(asctime)s - %(levelname)s - %(message)s"
logging.basicConfig(level=logging.DEBUG,filename='log.txt',format=LOG_FORMAT)
sh=logging.StreamHandler()
sh.setLevel(logging.DEBUG)
sh.setFormatter(logging.Formatter(LOG_FORMAT))
logger=logging.getLogger('logger')
logger.addHandler(sh)
以上代码,设定log的级别,同时输出到屏幕和指定的文件