Java教程

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

本文主要是介绍logger日志重复打印问题-解决,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
    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日志重复打印问题-解决的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!