logger.info('If you are using Python {}, prefer {feature} of course!',3.6,feature='f-strings')n1="cool"n2= [1, 2,3]logger.info(f'If you are using Python {n1}, prefer {n2} of course!')运行结果2020-03-0716:19:25.363|INFO|__main__:<module>:43 -IfyouareusingPython3.6,preferf-stringsofcourse!2020-03-0716:19:25.364|INFO|__main__:<module>:46 -IfyouareusingPythoncool,prefer [1, 2,3]ofcourse!
importtimefromloguruimportloggerfrompathlibimportPathproject_path=Path.cwd().parentlog_path=Path(project_path,"log")t=time.strftime("%Y_%m_%d")classLoggings:__instance=Nonelogger.add(f"{log_path}/interface_log_{t}.log",rotation="500MB",encoding="utf-8",enqueue=True, retention="10 days")def__new__(cls,*args,**kwargs):ifnotcls.__instance:cls.__instance=super(Loggings,cls).__new__(cls,*args,**kwargs)returncls.__instancedefinfo(self,msg):returnlogger.info(msg)defdebug(self,msg):returnlogger.debug(msg)defwarning(self,msg):returnlogger.warning(msg)deferror(self,msg):returnlogger.error(msg)loggings=Loggings()if__name__=='__main__':loggings.info("中文test")loggings.debug("中文test")loggings.warning("中文test")loggings.error("中文test")logger.info('If you are using Python {}, prefer {feature} of course!',3.6,feature='f-strings')n1="cool"n2= [1, 2,3]logger.info(f'If you are using Python {n1}, prefer {n2} of course!')