通过python封装日志
方式一:
通过python自带的logging模块进行封装
log 日志级别 NOTSET=0,DEBUG=10,INFO=20,WARNING=30,ERROR=40,CRITICAL=50
代码示例:
import time import os import logging currrent_path = os.path.dirname(__file__) log_path = os.path.join(currrent_path,'../logs') class LogUtils: def __init__(self,log_path=log_path): self.logfile_path = log_path # 创建日志对象logger self.logger = logging.getLogger(__name__) # 设置日志级别 self.logger.setLevel(level=logging.INFO) # 设置日志的格式 formatter = logging.Formatter('%(asctime)s - %(filename)s[line:%(lineno)d] - %(levelname)s: %(message)s') """在log文件中输出日志""" # 日志文件名称显示一天的日志 self.log_name_path = os.path.join(self.logfile_path, "UI_Test_%s" % time.strftime('%Y_%m