首页 > 其他 > 详细

logger日志重复打印问题-解决

时间:2021-05-21 22:19:52      阅读:31      评论:0      收藏:0      [点我收藏+]
    def getlogger(self):
        self.logger = logging.getLogger()
        
        self.logger.setLevel(logging.DEBUG)

        rp = strftime(%Y%m%d%H%M, localtime(time()))
        log_path = os.path.dirname(os.getcwd()) + /logs/
        errorlog_name = log_path + rp + _error + .log
        infolog_name = log_path + rp + _info + .log

        f1_handler = logging.FileHandler(errorlog_name, encoding=utf-8)
        f1_handler.setLevel(logging.ERROR)
        f2_handler = logging.FileHandler(infolog_name, encoding=utf-8)
        f2_handler.setLevel(logging.INFO)

        c_handler = logging.StreamHandler()
        c_handler.setLevel(logging.INFO)

        formatter = logging.Formatter(%(asctime)s - %(levelname)s - %(filename)s[:%(funcName)s - %(lineno)d] - %(message)s)
        f1_handler.setFormatter(formatter)
        f2_handler.setFormatter(formatter)
        c_handler.setFormatter(formatter)

        self.logger.addHandler(f1_handler)
        self.logger.addHandler(f2_handler)
        self.logger.addHandler(c_handler)

        return self.logger

技术分享图片

 

 

    def getlogger(self):
        self.logger = logging.getLogger()
        self.logger.handlers.clear()
        self.logger.setLevel(logging.DEBUG)
        ...
        ...

技术分享图片

 

logger日志重复打印问题-解决

原文:https://www.cnblogs.com/YY-kele/p/14796999.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!