-
-
Notifications
You must be signed in to change notification settings - Fork 48.7k
Add decorators to repo #11613
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add decorators to repo #11613
Changes from all commits
9a85183
2221fec
2f5739e
33f23e5
6679f4c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import logging | ||
import tzlocal | ||
from functools import wraps | ||
from datetime import datetime | ||
|
||
|
||
def log_entry_and_exit(func): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please provide return type hint for the function: As there is no test file in this pull request nor any test function or class in the file Please provide type hint for the parameter: |
||
"""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): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please provide return type hint for the function: As there is no test file in this pull request nor any test function or class in the file Please provide type hint for the parameter: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please provide return type hint for the function: As there is no test file in this pull request nor any test function or class in the file Please provide type hint for the parameter: |
||
print(f"My name is {name}") | ||
|
||
|
||
# Fucntion call | ||
my_func("John Doe") |
There was a problem hiding this comment.
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 functionlog_entry_and_exit
Please provide type hint for the parameter:
func