# -*-coding:utf-8 -*- #
# ---------------------------------------------------------------------------
# ProjectName:   框架
# FileName:      log.py
# Author:       xxxxxxx
# Datetime:     2023/11/4 9:43
# Description:
# 命名规范：文件名全小写+下划线，类名大驼峰，方法和变量小写+下划线连接，
# 常量大写，变量和常量用名词，方法用动词
# ---------------------------------------------------------------------------
import logging
import os


def write_log():
    """创建写入日志对象"""
    logger = logging.getLogger(name="test")
    # 获取日志目录
    log_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), "report/log/InterfaceAutoTest.log")
    # 文件的操作模式
    handler = logging.FileHandler(log_path, mode="a", encoding="utf-8")
    # 显示的格式
    format = logging.Formatter('%(asctime)s - %(filename)s[line:%(lineno)d] - %(levelname)s: %(message)s - %(name)s')
    handler.setFormatter(format)
    logger.addHandler(handler)
    return logger