Python +appium logger

封装日志模块

import logging


def get_log():
    # 配置日志参数
    logger = logging.getLogger()
    logger.setLevel(logging.INFO)

    logfile = 'C://Users/EDZ/PycharmProjects/untitled/appium_SH/report/logs/runlog.logs'

    fh = logging.FileHandler(logfile)   # 日志输出到文件
    fh.setLevel(logging.INFO)
    ch = logging.StreamHandler()   # 日志输出到控制台
    ch.setLevel(logging.INFO)

    formatter = logging.Formatter('%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s:%(message)s')
    fh.setFormatter(formatter)
    ch.setFormatter(formatter)

    logger.addHandler(fh)
    logger.addHandler(ch)

    return logger


logger = get_log()

 

你可能感兴趣的:(Python +appium logger)