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, log_params=("param",))
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 |
log_params | A tuple of parameter names to be logged with their values in 'extra' | () |
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.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 13d8184301b626ab84ae08163912ff1e7431eec02ad4d281af408131961dde44 |
|
MD5 | b47d4775c8be61625c214c38316d8e27 |
|
BLAKE2b-256 | 92163504da533ed7abcb7545f248831ef54626c20b070ceb46a890f8d7c496f6 |
Close
Hashes for sag_py_execution_time_decorator-1.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 093dfb83c4a2326cc89431326fc3d196d5cbbccf599672a2e6b6948d493d74e3 |
|
MD5 | ba8153e9f055ed02d80bc70487798f6d |
|
BLAKE2b-256 | 5f3b99f652538a5d6e7892f4b3a718a460cd99d28efd12c7a691c0a0c05cce61 |