playwright-master/tools/get_log.py

34 lines
1.1 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import logging.handlers
import os
import time
from tools.config import PRO_PATH
item_path = os.path.dirname(PRO_PATH)
log_path = item_path+"\logs"
print(log_path)
class GetLog:
__logger = None
# 获取日志器
@classmethod
def get_log(cls):
if cls.__logger is None:
cls.__logger = logging.getLogger()
cls.__logger.setLevel(logging.INFO)
filename = os.path.join(log_path, f'{time.strftime("%Y%m%d-%H%M%S", time.localtime())}.log')
print(filename)
fh = logging.handlers.TimedRotatingFileHandler(filename,
when='midnight', interval=1, backupCount=3, encoding="utf-8")
"""
when='midnight':一天一夜
interval=1每隔一个when生成一个日志文件
backupCount=7保存7天的日志备份数量
"""
fmt = logging.Formatter(
"%(asctime)s --%(name)s-- %(filename)s.%(funcName)s():line %(lineno)d [%(levelname)s]:%(message)s")
fh.setFormatter(fmt)
cls.__logger.addHandler(fh)
return cls.__logger