log 处理
保存文件, 并打印到屏幕
import logging
def set_log(log_file='log.log'):
logging.basicConfig(
level = logging.INFO,
handlers= [logging.StreamHandler(), logging.FileHandler(log_file)],
format = '[%(asctime)s] %(levelname)s (%(filename)s:%(lineno)d) %(message)s',
datefmt = '%y-%m-%d %H:%M:%S' )
文件和屏幕显示不同级别内容
file_handler = logging.FileHandler(p.logfile)
file_handler.setLevel(logging.WARN)
logging.basicConfig(level=logging.INFO,
format='[%(asctime)s] %(levelname)s (%(filename)s:%(lineno)d) %(message)s',
datefmt='%y-%m-%d %H:%M:%S',
handlers=[logging.StreamHandler(), file_handler],
)
--- 她说, 她是仙,她不是神