diff --git a/utils/__init__.py b/utils/__init__.py new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/utils/decorators/__init__.py b/utils/decorators/__init__.py new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/utils/decorators/log_entry_and_exit.py b/utils/decorators/log_entry_and_exit.py new file mode 100644 index 000000000000..7244b6b087fb --- /dev/null +++ b/utils/decorators/log_entry_and_exit.py @@ -0,0 +1,42 @@ +from datetime import datetime +from functools import wraps +import logging + +import tzlocal + + +def log_entry_and_exit(func): + """Log starting time and finish time of funciton""" + + # Setiing local timezone + local_tz = tzlocal.get_localzone() + # Configure logging + logging.basicConfig( + level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s" + ) + + @wraps(func) + def wrapper(*args, **kwargs): + start_time = datetime.now(tz=local_tz) + logging.info(f"Function '{func.__name__}' started at {start_time}") + return_value = func(*args, *kwargs) + end_time = datetime.now(tz=local_tz) + logging.info(f"Function '{func.__name__}' ended at {end_time}") + return return_value + + return wrapper + + +""" +Example usage: +""" + + +# Function declaration +@log_entry_and_exit +def my_func(name): + print(f"My name is {name}") + + +# Fucntion call +my_func("John Doe")