创建logger.py文件放置在框架目录Common文件夹下,logger.py代码如下:
# _*_ coding: utf-8 _*_ import logging import time class Logger(object): def __init__(self, logger): self.logger = logging.getLogger(logger) self.logger.setLevel(logging.DEBUG) rq = time.strftime('%Y%m%d%H%M', time.localtime(time.time())) log_path = '../log/' log_name = log_path + rq + '.log' fh = logging.FileHandler(log_name) fh.setLevel(logging.INFO) # 再创建一个handler,用于输出到控制台 ch = logging.StreamHandler() ch.setLevel(logging.INFO) # 定义handler的输出格式 formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') fh.setFormatter(formatter) ch.setFormatter(formatter) # 给logger添加handler self.logger.addHandler(fh) self.logger.addHandler(ch) def getlog(self): return self.logger
调用
来源https://zhuanlan.zhihu.com/p/85388606
标签:appium,ch,logging,log,Python,self,time,logger,日志 From: https://www.cnblogs.com/may18/p/17722393.html