Skip to content
Closed
Show file tree
Hide file tree
Changes from 4 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
Empty file added utils/__init__.py
Empty file.
Empty file added utils/decorators/__init__.py
Empty file.
39 changes: 39 additions & 0 deletions utils/decorators/log_entry_and_exit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import logging
import tzlocal
from functools import wraps
from datetime import datetime


def log_entry_and_exit(func):

Check failure on line 7 in utils/decorators/log_entry_and_exit.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (I001)

utils/decorators/log_entry_and_exit.py:1:1: I001 Import block is un-sorted or un-formatted

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide return type hint for the function: log_entry_and_exit. If the function does not return a value, please provide the type hint as: def function() -> None:

As there is no test file in this pull request nor any test function or class in the file utils/decorators/log_entry_and_exit.py, please provide doctest for the function log_entry_and_exit

Please provide type hint for the parameter: func

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide return type hint for the function: log_entry_and_exit. If the function does not return a value, please provide the type hint as: def function() -> None:

As there is no test file in this pull request nor any test function or class in the file utils/decorators/log_entry_and_exit.py, please provide doctest for the function log_entry_and_exit

Please provide type hint for the parameter: 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):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide return type hint for the function: wrapper. If the function does not return a value, please provide the type hint as: def function() -> None:

As there is no test file in this pull request nor any test function or class in the file utils/decorators/log_entry_and_exit.py, please provide doctest for the function wrapper

Please provide type hint for the parameter: args

Please provide type hint for the parameter: 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):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide return type hint for the function: my_func. If the function does not return a value, please provide the type hint as: def function() -> None:

As there is no test file in this pull request nor any test function or class in the file utils/decorators/log_entry_and_exit.py, please provide doctest for the function my_func

Please provide type hint for the parameter: name

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide return type hint for the function: my_func. If the function does not return a value, please provide the type hint as: def function() -> None:

As there is no test file in this pull request nor any test function or class in the file utils/decorators/log_entry_and_exit.py, please provide doctest for the function my_func

Please provide type hint for the parameter: name

print(f"My name is {name}")

#Fucntion call
my_func("John Doe")
Loading