zoukankan      html  css  js  c++  java
  • unittest使用的时候,print的东西可以在html详情里面显示,但是又想打印在日志中,那就修logging模块中的info方法,使用装饰器

    def print_msg(fun):
        def innfun_(self,msg,*args,**kwargs):
            print(msg)
            return fun(self,msg,*args,**kwargs)
    
    
    class Logger(Filterer):
        def __init__(self, name, level=NOTSET):
            """
            Initialize the logger with a name and an optional level.
            """
            Filterer.__init__(self)
            self.name = name
            self.level = _checkLevel(level)
            self.parent = None
            self.propagate = True
            self.handlers = []
            self.disabled = False
            self._cache = {}
    
        def setLevel(self, level):
            """
            Set the logging level of this logger.  level must be an int or a str.
            """
            self.level = _checkLevel(level)
            self.manager._clear_cache()
        @print_msg             # 添加装饰器
        def debug(self, msg, *args, **kwargs):
            """
            Log 'msg % args' with severity 'DEBUG'.
    
            To pass exception information, use the keyword argument exc_info with
            a true value, e.g.
    
            logger.debug("Houston, we have a %s", "thorny problem", exc_info=1)
            """
            if self.isEnabledFor(DEBUG):
                self._log(DEBUG, msg, args, **kwargs)
    
        def info(self, msg, *args, **kwargs):
            """
            Log 'msg % args' with severity 'INFO'.
    
            To pass exception information, use the keyword argument exc_info with
            a true value, e.g.
    
            logger.info("Houston, we have a %s", "interesting problem", exc_info=1)
            """
            if self.isEnabledFor(INFO):
                self._log(INFO, msg, args, **kwargs)    
  • 相关阅读:
    通用数据级权限控制解决方案的实现(二)(转)
    linux copy file to window
    日历 存储过程
    ssas 日期 时间维度表 sql 代码
    Dynamic CRM常用代码记录
    跨服务器查询sql (摘要)
    验证码实现
    office文档转pdf
    页面导出生成pdf,使用wkhtmltopdf第三方工具
    iTextSharp简单生成pdf和操作pdf添加水印
  • 原文地址:https://www.cnblogs.com/tarzen213/p/13903478.html
Copyright © 2011-2022 走看看