A decorator for methods to log the execution time (sync and async)
Project description
sag_py_execution_time_decorator
A decorator for methods to log the execution time (sync and async)
What it does
- Logs the execution time in milliseconds
Sample log entry:
decorated_sync_method took 1000 ms.
The entry contains "function_name" and "execution_time" as extra data.
Installation
pip install sag-py-execution-time-decorator
How to use
Decorate your methods like that:
from sag_py_execution_time_decorator.execution_time_decorator import log_execution_time
@log_execution_time()
def decorated_sync_method(param: str) -> str:
time.sleep(SLEEP_TIME_MS / 1000)
return f"test: {param}"
@log_execution_time(log_level=logging.ERROR)
async def decorated_async_method(param: str) -> str:
await asyncio.sleep(SLEEP_TIME_MS / 1000)
return f"test: {param}"
Optional arguments:
Argument | Description | Default |
---|---|---|
log_level | The log level integar. Use logging.* constants | logging.INFO |
logger_name | The name of the logger that is internally used for logging.getLogger | execution_time_decorator |
How to start developing
With vscode
Just install vscode with dev containers extension. All required extensions and configurations are prepared automatically.
With pycharm
- Install latest pycharm
- Install pycharm plugin BlackConnect
- Install pycharm plugin Mypy
- Configure the python interpreter/venv
- pip install requirements-dev.txt
- pip install black[d]
- Ctl+Alt+S => Check Tools => BlackConnect => Trigger when saving changed files
- Ctl+Alt+S => Check Tools => BlackConnect => Trigger on code reformat
- Ctl+Alt+S => Click Tools => BlackConnect => "Load from pyproject.yaml" (ensure line length is 120)
- Ctl+Alt+S => Click Tools => BlackConnect => Configure path to the blackd.exe at the "local instance" config (e.g. C:\Python310\Scripts\blackd.exe)
- Ctl+Alt+S => Click Tools => Actions on save => Reformat code
- Restart pycharm
How to publish
- Update the version in setup.py and commit your change
- Create a tag with the same version number
- Let github do the rest
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for sag-py-execution-time-decorator-1.0.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 78261662d64d862fd5c7e7704b59bec2445d0467b4594000488786f965d301a6 |
|
MD5 | b67e24027865051e3f5886e293e7086a |
|
BLAKE2b-256 | 5ff899e0bae132931bb60d700e1914b0a13c3b7e201fba1e167f7b1f8c883330 |
Close
Hashes for sag_py_execution_time_decorator-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 241fd2bbb6cd960d71d0eacf04f737d0bf18beaf2aedf9dc48a1c7bc6c079f05 |
|
MD5 | 015889388dd832cd80753afe63edd7b2 |
|
BLAKE2b-256 | 441658a3c38ef5619f8d8ec620004f0946f0011351691dd4952eefd3c9bffb54 |