Skip to content

Commit 2713377

Browse files
📚⚡ docs(Usage): Add Documentation for execution_tracker Decorator
1 parent 9272093 commit 2713377

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

docs/usage.rst

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,53 @@ Send Logs Command
120120
121121
This command will attach the log directory and send a zip file to the provided email address.
122122

123+
Execution Tracker Decorator
124+
---------------------------
125+
126+
The ``execution_tracker`` decorator is used to log the performance metrics of any function. It tracks execution time and the number of database queries for decorated function (if enabled).
127+
128+
Example Usage:
129+
130+
.. code-block:: python
131+
132+
from django_logging.decorators import execution_tracker
133+
134+
135+
@execution_tracker(
136+
logging_level=logging.INFO,
137+
log_queries=True,
138+
query_threshold=10,
139+
query_exceed_warning=False,
140+
)
141+
def some_function():
142+
# function code
143+
pass
144+
145+
**Arguments:**
146+
147+
- ``logging_level`` (``int``): The logging level at which performance details will be logged. Defaults to ``logging.INFO``.
148+
149+
- ``log_queries`` (``bool``): Whether to log the number of database queries for decorated function(if ``DEBUG`` is ``True`` in your settings). If ``log_queries=True``, the number of queries will be included in the logs. Defaults to ``False``.
150+
151+
- ``query_threshold`` (``int``): If provided, the number of database queries will be checked. If the number of queries exceeds the given threshold, a warning will be logged. Defaults to ``None``.
152+
153+
- ``query_exceed_warning`` (``bool``): Whether to log a ``WARNING`` message if the number of queries exceeds the threshold. Defaults to ``False``.
154+
155+
**Example Log Output:**
156+
157+
.. code-block:: shell
158+
159+
INFO | 'datetime' | execution_tracking | Performance Metrics for Function: 'some_function'
160+
Module: some_module
161+
File: /path/to/file.py, Line: 123
162+
Execution Time: 0 minute(s) and 0.2132 second(s)
163+
Database Queries: 15 queries (exceeds threshold of 10)
164+
165+
If `log_queries` is set to ``True`` but ``DEBUG`` is ``False``, a ``WARNING`` will be logged:
166+
167+
.. code-block:: shell
168+
169+
WARNING | 'datetime' | execution_tracking | DEBUG mode is disabled, so database queries are not tracked.
170+
To include the number of queries, set ``DEBUG`` to ``True`` in your Django settings.
171+
123172

0 commit comments

Comments
 (0)