Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/memos/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import functools
import time
import traceback

from memos.log import get_logger

Expand Down Expand Up @@ -35,6 +36,7 @@ def decorator(fn):
def wrapper(*args, **kwargs):
start = time.perf_counter()
exc_type = None
exc_message = None
result = None
success_flag = False

Expand All @@ -44,6 +46,7 @@ def wrapper(*args, **kwargs):
return result
except Exception as e:
exc_type = type(e)
exc_message = traceback.format_exc()
success_flag = False

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

status = "SUCCESS" if success_flag else "FAILED"
status_info = f", status: {status}"

if not success_flag and exc_type is not None:
status_info += f", error: {exc_type.__name__}"
status_info += (
f", error_type: {exc_type.__name__}, error_message: {exc_message}"
)

msg = (
f"[TIMER_WITH_STATUS] {log_prefix or fn.__name__} "
f"took {elapsed_ms:.0f} ms{status_info}, args: {ctx_str}"
f", result: {result}"
)

logger.info(msg)
Expand Down