Unverified Commit d86285a4 authored by youkaichao's avatar youkaichao Committed by GitHub
Browse files

[Core][Logging] Add last frame information for better debugging (#4278)

parent d87f39e9
...@@ -83,13 +83,27 @@ def _trace_calls(log_path, root_dir, frame, event, arg=None): ...@@ -83,13 +83,27 @@ def _trace_calls(log_path, root_dir, frame, event, arg=None):
return return
# Log every function call or return # Log every function call or return
try: try:
last_frame = frame.f_back
if last_frame is not None:
last_filename = last_frame.f_code.co_filename
last_lineno = last_frame.f_lineno
last_func_name = last_frame.f_code.co_name
else:
# initial frame
last_filename = ""
last_lineno = 0
last_func_name = ""
with open(log_path, 'a') as f: with open(log_path, 'a') as f:
if event == 'call': if event == 'call':
f.write(f"{datetime.datetime.now()} Call to" f.write(f"{datetime.datetime.now()} Call to"
f" {func_name} in {filename}:{lineno}\n") f" {func_name} in {filename}:{lineno}"
f" from {last_func_name} in {last_filename}:"
f"{last_lineno}\n")
else: else:
f.write(f"{datetime.datetime.now()} Return from" f.write(f"{datetime.datetime.now()} Return from"
f" {func_name} in {filename}:{lineno}\n") f" {func_name} in {filename}:{lineno}"
f" to {last_func_name} in {last_filename}:"
f"{last_lineno}\n")
except NameError: except NameError:
# modules are deleted during shutdown # modules are deleted during shutdown
pass pass
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment