import time from loguru import logger from pathlib import Path # 获取当前文件路径的父目录 project_path = Path.cwd().parent log_path = Path(project_path, "log") t = time.strftime("%Y_%m_%d") class Loggings: __instance = None logger.add(f"{log_path}/interface_log_{t}.log", rotation="500MB", encoding="utf-8", enqueue=True, retention="10 days") def __new__(cls, *args, **kwargs): if not cls.__instance: cls.__instance = super(Loggings, cls).__new__(cls, *args, **kwargs) return cls.__instance def info(self, msg): return logger.info(msg) def debug(self, msg): return logger.debug(msg) def warning(self, msg): return logger.warning(msg) def error(self, msg): return logger.error(msg) loggings = Loggings() if __name__ == '__main__': loggings.info("info_test") loggings.debug("debug_test") loggings.warning("warning_test") loggings.error("error_test")
Loguru封装类,可直接使用
最新推荐文章于 2024-07-29 14:37:54 发布