Skip to content

Commit d8bace4

Browse files
authored
feat: add timer log (#793)
## Description <!-- Please include a summary of the changes below; Fill in the issue number that this PR addresses (if applicable); Fill in the related MemOS-Docs repository issue or PR link (if applicable); Mention the person who will review this PR (if you know who it is); Replace (summary), (issue), (docs-issue-or-pr-link), and (reviewer) with the appropriate information. 请在下方填写更改的摘要; 填写此 PR 解决的问题编号(如果适用); 填写相关的 MemOS-Docs 仓库 issue 或 PR 链接(如果适用); 提及将审查此 PR 的人(如果您知道是谁); 替换 (summary)、(issue)、(docs-issue-or-pr-link) 和 (reviewer) 为适当的信息。 --> Summary: (summary) Fix: #(issue) Docs Issue/PR: (docs-issue-or-pr-link) Reviewer: @(reviewer) ## Checklist: - [ ] I have performed a self-review of my own code | 我已自行检查了自己的代码 - [ ] I have commented my code in hard-to-understand areas | 我已在难以理解的地方对代码进行了注释 - [ ] I have added tests that prove my fix is effective or that my feature works | 我已添加测试以证明我的修复有效或功能正常 - [ ] I have created related documentation issue/PR in [MemOS-Docs](https://github.com/MemTensor/MemOS-Docs) (if applicable) | 我已在 [MemOS-Docs](https://github.com/MemTensor/MemOS-Docs) 中创建了相关的文档 issue/PR(如果适用) - [ ] I have linked the issue to this PR (if applicable) | 我已将 issue 链接到此 PR(如果适用) - [ ] I have mentioned the person who will review this PR | 我已提及将审查此 PR 的人
2 parents f0af4e1 + 1c7ef04 commit d8bace4

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/memos/utils.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import functools
22
import time
3+
import traceback
34

45
from memos.log import get_logger
56

@@ -35,6 +36,7 @@ def decorator(fn):
3536
def wrapper(*args, **kwargs):
3637
start = time.perf_counter()
3738
exc_type = None
39+
exc_message = None
3840
result = None
3941
success_flag = False
4042

@@ -44,6 +46,7 @@ def wrapper(*args, **kwargs):
4446
return result
4547
except Exception as e:
4648
exc_type = type(e)
49+
exc_message = traceback.format_exc()
4750
success_flag = False
4851

4952
if fallback is not None and callable(fallback):
@@ -76,13 +79,15 @@ def wrapper(*args, **kwargs):
7679

7780
status = "SUCCESS" if success_flag else "FAILED"
7881
status_info = f", status: {status}"
79-
8082
if not success_flag and exc_type is not None:
81-
status_info += f", error: {exc_type.__name__}"
83+
status_info += (
84+
f", error_type: {exc_type.__name__}, error_message: {exc_message}"
85+
)
8286

8387
msg = (
8488
f"[TIMER_WITH_STATUS] {log_prefix or fn.__name__} "
8589
f"took {elapsed_ms:.0f} ms{status_info}, args: {ctx_str}"
90+
f", result: {result}"
8691
)
8792

8893
logger.info(msg)

0 commit comments

Comments
 (0)