将日志同时输出到控制台和文件中
import os
import logging
from logging import handlers
import logging.config
logger = logging.getLogger()
logger.setLevel(level=logging.DEBUG)
# 获取绝对路径
path = os.path.abspath('.')
# 日志打印格式
formatter = logging.Formatter('%(asctime)s - %(filename)s[line:%(lineno)d] - %(levelname)s: %(message)s')
#将日志输出到文件
file_handler = handlers.TimedRotatingFileHandler(filename=path+'\\send.log', when='D')
file_handler.setFormatter(formatter)
# 将日志打印到控制台
console_handler = logging.StreamHandler()
console_handler.setFormatter(formatter)
logger.addHandler(console_handler)
logger.addHandler(file_handler)
参考:https://www.cnblogs.com/yyds/p/6901864.html(讲解超级详细)
https://blog.csdn.net/u010895119/article/details/79470443