A simple Django application that helps you track the execution time of functions, class views, and middleware ( with elasticsearch optional for logging)
Project description
========================== Django-Time-Logs
A Django middleware-based application that logs the path, creation date, and duration of each request.
Features
- Logs the request path (URL).
- Logs the creation date and time of the request.
- Logs the duration (time taken) for the request to complete.
- Easy to integrate into any Django project.
Installation
-
Clone the repository or download the app::
git clone https://github.com/Fattyk/django-time-logs.git or pip install django-time-logs
-
Add the app to your Django project's
INSTALLED_APPSinsettings.py::INSTALLED_APPS = [ ... 'django_time_logs', ... ]
-
Add the middleware to your
MIDDLEWARElist insettings.py::MIDDLEWARE = [ ... 'django_time_logs.middleware.TimeLoggerMiddleware', ... ]
-
Include the django-time-logs URLconf in your project urls.py like this::
path('', include('django_time_logs.urls')),
-
Start the development server and visit
/time-logsfor the logs.
Usage
Once installed, the app will automatically log the following details for every request:
- Path: The URL path of the request.
- Created Date: The timestamp when the request was made.
- Duration: The time taken (in seconds) for the request to complete.
Example Log Entry
::
Path: /api/data/
Created Date: 2023-10-01 12:34:56
Duration: 0.12 seconds
Configuration
You can customize the behavior of the logger by adding the following settings to your settings.py:
- TIME_LOGGER_INDEX: Define the elastic search index for the loggins if you're logging to elastic search
- WHERE_TO_LOG_REQUEST: Set to
ELASTICto log requests to a elastic search (default:ELASTIC). You can log toELASTICorFILE. Kindly note thatFILEoption is still in progress - TIME_LOG_TEMPLATE: (optional). You can customize this template in
settings.pyto use your custom template.
Example::
# settings.py
TIME_LOGGER_INDEX = 'elastic_time_logger'
WHERE_TO_LOG_REQUEST = ELASTIC
TIME_LOG_TEMPLATE = 'path-to-your-template.html'
Contributing
Contributions are welcome! Please follow these steps:
- Fork the repository.
- Create a new branch for your feature or bugfix.
- Submit a pull request.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Author
Fatai Kayode Ogundele – [ogundele.fatai.k@gmail.com]
Project Link: https://github.com/Fattyk/django-time-logs
Project details
Release history Release notifications | RSS feed
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_time_logs-0.1.0.tar.gz.
File metadata
- Download URL: django_time_logs-0.1.0.tar.gz
- Upload date:
- Size: 8.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
09132a18062a5e134fe81b362db5a99b12f8bd8829f298dd7ae99cd064ed1fdc
|
|
| MD5 |
2409dcf50aeae7bc3e834a8caae750e5
|
|
| BLAKE2b-256 |
aa35da249d6ddafc90d0c87466d715b6c08167b2b66bd4dc04e76e248361c706
|
File details
Details for the file django_time_logs-0.1.0-py3-none-any.whl.
File metadata
- Download URL: django_time_logs-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
478686a292d78a416d0b1701d990aac724df92995dbaa0a94e0a67a3b01bd158
|
|
| MD5 |
444b3c7ddc3ac4473b34eb35a904bd35
|
|
| BLAKE2b-256 |
8aab48b0d8452b4e7cbfb3fbee4a88ed4f6f89575789ac682c8d704d9268a228
|