Skip to main content

A Django app for logging HTTP requests and responses

Project description

Django MTG RES is a reusable Django app for logging HTTP requests and responses. It provides a simple way to track API calls, debug issues, and maintain audit logs of external service interactions.

Features

  • Log HTTP requests and responses with full metadata

  • Support for different request/response formats (JSON, text, etc.)

  • Flexible reference system to link logs to specific objects

  • Safe error handling to prevent logging failures from breaking your app

  • Admin interface for viewing and managing logs

Quick start

  1. Install django-mtg-res:

    pip install django-mtg-res
  2. Add “django_mtg_res” to your INSTALLED_APPS setting like this:

    INSTALLED_APPS = [
        ...
        'django_mtg_res',
    ]
  3. Run migrations to create the RequestLog model:

    python manage.py migrate
  4. Start using the RequestLog model in your code:

    from django_mtg_res.models import RequestLog
    import requests
    
    # Make an API call
    response = requests.get('https://api.example.com/data')
    
    # Log the request and response
    RequestLog.create_request_log(
        url='https://api.example.com/data',
        method='GET',
        request=None,  # No request body for GET
        response=response,
        ref_obj='User',
        ref_id='123',
        remarks='Fetching user data'
    )

Usage Examples

Basic logging:

from django_mtg_res.models import RequestLog

# Log a simple request
RequestLog.create_request_log(
    url='https://api.service.com/endpoint',
    method='POST',
    request={'key': 'value'},
    response={'result': 'success'},
    status_code=200
)

With reference objects:

# Log with reference to a specific model instance
RequestLog.create_request_log(
    url='https://payment.service.com/charge',
    method='POST',
    request=payment_data,
    response=payment_response,
    ref_obj='Order',
    ref_id=str(order.id),
    remarks='Payment processing'
)

Safe logging (won’t raise exceptions):

# This will not raise exceptions even if logging fails
RequestLog.create_request_log(
    url=api_url,
    request=request_data,
    response=response_data,
    safely_create=True  # Default is True
)

Admin Interface

The app includes Django admin integration. You can view and search request logs in the Django admin panel under “Request Logs”.

Requirements

  • Python >= 3.10

  • Django >= 4.0

  • requests >= 2.25.0

License

This project is licensed under the MIT License.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Support

If you encounter any issues or have questions, please open an issue on the project repository.

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_mtg_res-0.1.3.tar.gz (10.0 kB view details)

Uploaded Source

Built Distribution

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

django_mtg_res-0.1.3-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

Details for the file django_mtg_res-0.1.3.tar.gz.

File metadata

  • Download URL: django_mtg_res-0.1.3.tar.gz
  • Upload date:
  • Size: 10.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for django_mtg_res-0.1.3.tar.gz
Algorithm Hash digest
SHA256 39dfbb2f2771664d0e1d6b16a7ab777f6290a2364ab96a52e8b0bbd451c64f45
MD5 cdb3db54a954381bc1d2e49f0a69d826
BLAKE2b-256 2ba8c1cb0a0106418b0afb2a87d7d5a4e08e6a3fdce3446e47e0cdf74c102c83

See more details on using hashes here.

File details

Details for the file django_mtg_res-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: django_mtg_res-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 10.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for django_mtg_res-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 e13b379a37acd5f264a1e74d51e8dab52505d6af5dffbb86eb039dfe486b9f91
MD5 58480bac61cd56760371bf50d91f4bd3
BLAKE2b-256 7acc4c4bf353b949e2dbb28465e4ec2c96e7019d97a9257168a2f1d55bfa6dfb

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