Skip to main content

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

  1. Clone the repository or download the app::

    git clone https://github.com/Fattyk/django-time-logs.git or pip install django-time-logs

  2. Add the app to your Django project's INSTALLED_APPS in settings.py::

    INSTALLED_APPS = [ ... 'django_time_logs', ... ]

  3. Add the middleware to your MIDDLEWARE list in settings.py::

    MIDDLEWARE = [ ... 'django_time_logs.middleware.TimeLoggerMiddleware', ... ]

  4. Include the django-time-logs URLconf in your project urls.py like this::

    path('', include('django_time_logs.urls')),

  5. Start the development server and visit /time-logs for 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 ELASTIC to log requests to a elastic search (default: ELASTIC). You can log to ELASTIC or FILE. Kindly note that FILE option is still in progress
  • TIME_LOG_TEMPLATE: (optional). You can customize this template in settings.py to 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:

  1. Fork the repository.
  2. Create a new branch for your feature or bugfix.
  3. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_time_logs-0.1.0.tar.gz (8.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_time_logs-0.1.0-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

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

Hashes for django_time_logs-0.1.0.tar.gz
Algorithm Hash digest
SHA256 09132a18062a5e134fe81b362db5a99b12f8bd8829f298dd7ae99cd064ed1fdc
MD5 2409dcf50aeae7bc3e834a8caae750e5
BLAKE2b-256 aa35da249d6ddafc90d0c87466d715b6c08167b2b66bd4dc04e76e248361c706

See more details on using hashes here.

File details

Details for the file django_time_logs-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_time_logs-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 478686a292d78a416d0b1701d990aac724df92995dbaa0a94e0a67a3b01bd158
MD5 444b3c7ddc3ac4473b34eb35a904bd35
BLAKE2b-256 8aab48b0d8452b4e7cbfb3fbee4a88ed4f6f89575789ac682c8d704d9268a228

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page