Skip to content

Commit 1c7ef04

Browse files
author
harvey_xiang
committed
feat: add timer log
1 parent f0af4e1 commit 1c7ef04

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)