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)    
  • 相关阅读:
    Python 集合 深浅copy
    python基础(基础数据类型)
    python基础一
    Asp.net获取网站绝对路径的几种方法
    Ajax请求被缓存的几种处理方式
    说说字符编码
    linux学习记录
    mysql基础
    【Android开发入门】关于ListView中按钮监听器设置的解决方案
    线程同步小结
  • 原文地址:https://www.cnblogs.com/tarzen213/p/13903478.html
Copyright © 2011-2022 走看看