Python - 日志管理模块: Loguru的使用

详细见

自己封装的代码,可以直接使用

from loguru import logger
import os

logs_dir = f"{os.path.dirname(os.path.dirname(__file__))}/log"
file_name = 'ApiTestLogs'


class Loggings:
    __instance = None
    logger.add(f"{logs_dir}/{file_name}.log", rotation="500MB", encoding="utf-8", enqueue=True,
               retention="10 days")

    def __new__(cls, *args, **kwargs):
        if not cls.__instance:
            cls.__instance = super(Loggings, cls).__new__(cls, *args, **kwargs)

        return cls.__instance
    def __init__(self):
        self.className = self.__class__.__name__

    def info(self, msg):

        return logger.info(msg)

    def debug(self, msg):
        return logger.debug(msg)

    def warning(self, msg):
        return logger.warning(msg)

    def error(self, msg):
        '''
        打印错误信息
        '''
        return logger.error(msg)

    def exception(self,msg):
        '''
        打印异常信息方法
        '''
        return logger.exception(msg)

 

posted @ 2021-02-26 10:58  西西cc  阅读(156)  评论(0编辑  收藏  举报