(self, exc: Optional[Exception] = None, msg: Optional[str] = "")
| 93 | self.logger.success(self._template(caller_info, msg)) |
| 94 | |
| 95 | def error(self, exc: Optional[Exception] = None, msg: Optional[str] = ""): |
| 96 | frame = getframeinfo(currentframe().f_back) |
| 97 | caller_info = { |
| 98 | "module": getmodulename(frame.filename), |
| 99 | "filename": frame.filename, |
| 100 | "line": frame.lineno, |
| 101 | "function": frame.function, |
| 102 | } |
| 103 | excStr = "" |
| 104 | if exc is not None: |
| 105 | # 确保 exc 是异常对象,而不是字符串 |
| 106 | if isinstance(exc, BaseException): |
| 107 | excStr = "".join(format_exception(type(exc), exc, exc.__traceback__)) |
| 108 | else: |
| 109 | # 如果 exc 不是异常对象,只记录其字符串表示 |
| 110 | excStr = str(exc) |
| 111 | self.logger.error(self._template(caller_info, f"{msg}\n{excStr}")) |
| 112 | |
| 113 | def trace(self, msg: str): |
| 114 | frame = getframeinfo(currentframe().f_back) |
no test coverage detected