class MyLogger: def __init__(self,logger_name,filepath): cf = configparser.RawConfigParser() cf.read(Config_path,encoding='utf-8') self.logger_name=logger_name self.logger_level=cf["LOG"]["logger_level"] self.handler_level=cf["LOG"]["handler_level"] self.formatter=cf["LOG"]["formatter"] self.filepath=filepath def mylog(self): logger=logging.Logger(self.logger_name,self.logger_level) formatter = logging.Formatter(self.formatter) sh=logging.StreamHandler() sh.setLevel(self.handler_level) #设置过滤输出等级 sh.setFormatter(formatter) #设置输出格式 fh=logging.FileHandler(self.filepath,'a',encoding='utf-8') fh.setLevel(self.handler_level) #设置过滤输出等级 fh.setFormatter(formatter) #设置输出格式 logger.addHandler(sh) logger.addHandler(fh) return logger