Skip to content
Open
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
6 changes: 4 additions & 2 deletions Framework/Utilities/decorators.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
import time
import functools
from . import CommonUtil
from datetime import datetime

datetime_format = "%d-%b-%Y %H:%M:%S"

def logger(func):
"""Log the entry and exit of the decorated function"""

@functools.wraps(func)
def wrapper(*args, **kwargs):
start_time = time.perf_counter()
CommonUtil.ExecLog(None, f"Entering into function: {func.__name__!r}.", 5)
CommonUtil.ExecLog(None, f"{datetime.now().strftime(datetime_format)} | Entering into function: {func.__name__!r}.", 5)

result = func(*args, **kwargs)
end_time = time.perf_counter()
run_time = end_time - start_time

CommonUtil.ExecLog(
None,
f"Exited from function: {func.__name__!r}. Runtime: {run_time:.4f} secs.",
f"{datetime.now().strftime(datetime_format)} | Exited from function: {func.__name__!r}. Runtime: {run_time:.4f} secs.",
5,
)

Expand Down