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) ... ...