django-query-log


Namedjango-query-log JSON
Version 1.0.0 PyPI version JSON
download
home_pagehttps://github.com/dipee/django-query-log
SummaryA Django package for logging database query execution time and performance analysis for all Django requests
upload_time2025-07-19 08:37:46
maintainerNone
docs_urlNone
authorDipendra
requires_python>=3.8
licenseMIT
keywords django database query logging performance monitoring sql middleware n+1 optimization inspector debugging
VCS
bugtrack_url
requirements Django
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Django Query Log

[![PyPI version](https://badge.fury.io/py/django-query-log.svg)](https://badge.fury.io/py/django-query-log)
[![Python Support](https://img.shields.io/pypi/pyversions/django-query-log.svg)](https://pypi.org/project/django-query-log/)
[![Django Support](https://img.shields.io/badge/django-3.2%2B-brightgreen.svg)](https://www.djangoproject.com/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

A comprehensive Django package for logging database query execution time and performance analysis for all Django requests. Monitor your application's database performance with detailed insights, N+1 query detection, and customizable logging formats. Works with regular Django views, class-based views, and Django REST Framework APIs.

## Features

- 🚀 **Real-time Query Monitoring**: Track database queries for all Django requests
- 📊 **Performance Analysis**: Automatic detection of slow queries and performance bottlenecks
- 🔍 **N+1 Query Detection**: Identify and warn about N+1 query problems
- 🔄 **Duplicate Query Detection**: Find and report duplicate queries
- 📝 **Multiple Log Formats**: Support for JSON, compact, detailed, and custom formatters
- ⚙️ **Highly Configurable**: Extensive configuration options for different use cases
- 🎯 **Universal Django Support**: Works with function views, class-based views, and Django REST Framework
- 🔐 **Security**: Automatic sanitization of sensitive data in logs
- 📈 **Stack Trace Support**: Optional stack trace logging for query sources
- 🎨 **Custom Formatters**: Create your own log formatting logic

## Installation

Install using pip:

```bash
pip install django-query-log
```

For Django REST Framework support:

```bash
pip install django-query-log[drf]
```

Or install with development dependencies:

```bash
pip install django-query-log[dev]
```

## Quick Start

1. **Add to Django Settings**:

```python
# settings.py
INSTALLED_APPS = [
    # ... your other apps
    'django_query_log',
]

MIDDLEWARE = [
    # ... your other middleware
    'django_query_log.middleware.QueryLogMiddleware',
    # ... rest of your middleware
]

# Optional: Configure django-query-log
DJANGO_QUERY_LOG = {
    'ENABLED': True,
    'LOG_LEVEL': 'INFO',
    'LOGGER_NAME': 'django_query_log',
}
```

2. **Configure Logging** (optional):

```python
# settings.py
LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'handlers': {
        'query_log': {
            'level': 'INFO',
            'class': 'logging.StreamHandler',
            'formatter': 'verbose',
        },
    },
    'loggers': {
        'django_query_log': {
            'handlers': ['query_log'],
            'level': 'INFO',
            'propagate': False,
        },
    },
    'formatters': {
        'verbose': {
            'format': '{levelname} {asctime} {module} {message}',
            'style': '{',
        },
    },
}
```

3. **Start your Django server** and make requests to any Django view. Query logs will appear in your console!

## Usage Examples

### Basic Usage

Once installed and configured, django-query-log automatically logs database queries for all Django requests (views, APIs, admin, etc.):

```
[2024-01-15T10:30:45.123456] GET /api/users/ - Queries: 3, Total Time: 0.0157s
  User: admin (ID: 1)
  Performance Analysis:
    Average Query Time: 0.0052s
    Duplicate Queries: 0 queries in 0 groups
  Queries:
    1. [0.0031s] SELECT "auth_user"."id", "auth_user"."username", "auth_user"."email" FROM "auth_user" WHERE "auth_user"."is_active" = TRUE
    2. [0.0089s] SELECT "user_profile"."id", "user_profile"."user_id", "user_profile"."avatar" FROM "user_profile" WHERE "user_profile"."user_id" IN (1, 2, 3)
    3. [0.0037s] SELECT COUNT(*) AS "__count" FROM "auth_user" WHERE "auth_user"."is_active" = TRUE
  Response: 200 (1024 bytes)
```

### Using Different Formatters

**JSON Formatter** (great for structured logging):

```python
# settings.py
DJANGO_QUERY_LOG = {
    'FORMATTER_CLASS': 'django_query_log.formatters.JSONFormatter',
}
```

**Compact Formatter** (minimal output):

```python
# settings.py
DJANGO_QUERY_LOG = {
    'FORMATTER_CLASS': 'django_query_log.formatters.CompactFormatter',
}
```

Output:

```
[2024-01-15T10:30:45.123456] GET /api/users/ | queries=3 | time=0.016s | user=admin
```

**Detailed Formatter** (comprehensive information):

```python
# settings.py
DJANGO_QUERY_LOG = {
    'FORMATTER_CLASS': 'django_query_log.formatters.DetailedFormatter',
}
```

### Works with All Django Views

Django Query Log works seamlessly with all types of Django views:

**Function-based views:**

```python
def my_view(request):
    users = User.objects.all()  # Logged automatically
    return render(request, 'users.html', {'users': users})
```

**Class-based views:**

```python
class UserListView(ListView):
    model = User  # All queries logged automatically
    template_name = 'users.html'
```

**Django REST Framework views:**

```python
from rest_framework.viewsets import ModelViewSet

class UserViewSet(ModelViewSet):
    queryset = User.objects.all()  # All queries logged automatically
    serializer_class = UserSerializer
```

### Context Manager

Temporarily disable or enable logging for specific code blocks:

```python
from django_query_log.middleware import DjangoQueryLogContext

# Disable logging for this block
with DjangoQueryLogContext(enabled=False):
    users = User.objects.all()  # This won't be logged

# Enable logging (if disabled globally)
with DjangoQueryLogContext(enabled=True):
    users = User.objects.all()  # This will be logged
```

## Configuration

### Complete Configuration Options

```python
# settings.py
DJANGO_QUERY_LOG = {
    # Enable/disable query logging
    'ENABLED': True,

    # Minimum query execution time to log (in seconds)
    'MIN_QUERY_TIME': 0.001,

    # Maximum number of queries to log per request
    'MAX_QUERIES_PER_REQUEST': 100,

    # Log level for query information
    'LOG_LEVEL': 'INFO',  # DEBUG, INFO, WARNING, ERROR, CRITICAL

    # Logger name to use
    'LOGGER_NAME': 'django_query_log',

    # Include request information in logs
    'INCLUDE_REQUEST_INFO': True,

    # Include response information in logs
    'INCLUDE_RESPONSE_INFO': True,

    # Include user information in logs
    'INCLUDE_USER_INFO': True,

    # Include SQL query text in logs
    'INCLUDE_SQL': True,

    # Include query execution stack trace
    'INCLUDE_STACK_TRACE': False,

    # Sensitive parameters to exclude from logs
    'SENSITIVE_PARAMS': ['password', 'token', 'secret', 'key'],

    # Only log queries for specific paths (empty list means all paths)
    'INCLUDE_PATHS': [],

    # Exclude queries for specific paths
    'EXCLUDE_PATHS': ['/admin/', '/static/', '/media/'],

    # Custom formatter class
    'FORMATTER_CLASS': 'django_query_log.formatters.DefaultFormatter',

    # Include duplicate query detection
    'DETECT_DUPLICATE_QUERIES': True,

    # Warn about N+1 query problems
    'DETECT_N_PLUS_ONE': True,

    # Include query performance analysis
    'INCLUDE_PERFORMANCE_ANALYSIS': True,
}
```

### Configuration Examples

**Production Environment** (minimal logging):

```python
DJANGO_QUERY_LOG = {
    'ENABLED': True,
    'MIN_QUERY_TIME': 0.01,  # Only log slow queries
    'MAX_QUERIES_PER_REQUEST': 50,
    'LOG_LEVEL': 'WARNING',
    'INCLUDE_SQL': False,  # Don't log SQL in production
    'FORMATTER_CLASS': 'django_query_log.formatters.CompactFormatter',
    'EXCLUDE_PATHS': ['/admin/', '/static/', '/media/', '/health/'],
}
```

**Development Environment** (detailed logging):

```python
DJANGO_QUERY_LOG = {
    'ENABLED': True,
    'MIN_QUERY_TIME': 0.001,
    'LOG_LEVEL': 'DEBUG',
    'INCLUDE_STACK_TRACE': True,
    'FORMATTER_CLASS': 'django_query_log.formatters.DetailedFormatter',
    'DETECT_N_PLUS_ONE': True,
    'DETECT_DUPLICATE_QUERIES': True,
}
```

**API-Only Logging**:

```python
DJANGO_QUERY_LOG = {
    'ENABLED': True,
    'INCLUDE_PATHS': ['/api/'],  # Only log API requests
    'EXCLUDE_PATHS': ['/api/health/', '/api/metrics/'],
}
```

## Performance Features

### N+1 Query Detection

Django Query Log automatically detects potential N+1 query problems:

```
N+1 Query Issues: 1 detected
  - Pattern executed 25 times (0.1234s total)
```

### Duplicate Query Detection

Identifies repeated identical queries:

```
Duplicate Queries: 15 queries in 3 groups
```

### Slow Query Identification

Highlights the slowest queries in each request:

```
Slowest Queries:
  1. [0.0892s] SELECT * FROM "products" WHERE "products"."category_id" = 1
  2. [0.0445s] SELECT COUNT(*) FROM "orders" WHERE "orders"."user_id" = 123
```

## Custom Formatters

Create your own custom formatter:

```python
# myapp/formatters.py
from django_query_log.formatters import BaseFormatter

class MyCustomFormatter(BaseFormatter):
    def format_log_entry(self, log_data):
        request_info = log_data.get('request', {})
        performance = log_data.get('performance_analysis', {})

        return f"API {request_info.get('method')} {request_info.get('path')} " \
               f"executed {performance.get('total_queries', 0)} queries " \
               f"in {performance.get('total_time', 0):.3f}s"

# settings.py
DJANGO_QUERY_LOG = {
    'FORMATTER_CLASS': 'myapp.formatters.MyCustomFormatter',
}
```

## Integration with Logging Systems

### Structured Logging with JSON

```python
import json
import logging

class JSONLogHandler(logging.StreamHandler):
    def emit(self, record):
        try:
            # Parse the log message as JSON if possible
            log_data = json.loads(record.getMessage())
            # Send to your logging service (e.g., ELK, Splunk, etc.)
            super().emit(record)
        except json.JSONDecodeError:
            super().emit(record)

# settings.py
LOGGING = {
    'handlers': {
        'json_query_log': {
            'level': 'INFO',
            '()': 'myapp.logging.JSONLogHandler',
        },
    },
    'loggers': {
        'django_query_log': {
            'handlers': ['json_query_log'],
            'level': 'INFO',
        },
    },
}

DJANGO_QUERY_LOG = {
    'FORMATTER_CLASS': 'django_query_log.formatters.JSONFormatter',
}
```

## Requirements

- Python 3.8+
- Django 3.2+
- Django REST Framework 3.12.0+ (optional)

## Compatibility

- **Django**: 3.2, 4.0, 4.1, 4.2, 5.0
- **Python**: 3.8, 3.9, 3.10, 3.11, 3.12
- **Django REST Framework**: 3.12.0+ (optional for API logging)

## Contributing

We welcome contributions! Please see our [Contributing Guidelines](CONTRIBUTING.md) for details.

### Development Setup

1. Clone the repository:

```bash
git clone https://github.com/dipee/django-query-log.git
cd django-query-log
```

2. Install development dependencies:

```bash
pip install -e .[dev]
```

3. Run tests:

```bash
pytest
```

4. Run linting:

```bash
black .
flake8 .
isort .
mypy .
```

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## Changelog

See [CHANGELOG.md](CHANGELOG.md) for release history.

## Support

- **Documentation**: [https://django-query-log.readthedocs.io/](https://django-query-log.readthedocs.io/)
- **Issues**: [https://github.com/dipee/django-query-log/issues](https://github.com/dipee/django-query-log/issues)
- **Discussions**: [https://github.com/dipee/django-query-log/discussions](https://github.com/dipee/django-query-log/discussions)

## Acknowledgments

- Inspired by Django Debug Toolbar's query logging capabilities
- Built for Django developers who need production-ready query monitoring for all types of views
- Thanks to all contributors who help improve this package

---

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/dipee/django-query-log",
    "name": "django-query-log",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "Dipendra <dipee.info@gmail.com>",
    "keywords": "django, database, query, logging, performance, monitoring, sql, middleware, n+1, optimization, inspector, debugging",
    "author": "Dipendra",
    "author_email": "Dipendra <dipee.info@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/cf/1b/1158e33929902ac29b76c4ca03017e9ee8eb2b78abb8c2f4a632989de305/django_query_log-1.0.0.tar.gz",
    "platform": "any",
    "description": "# Django Query Log\n\n[![PyPI version](https://badge.fury.io/py/django-query-log.svg)](https://badge.fury.io/py/django-query-log)\n[![Python Support](https://img.shields.io/pypi/pyversions/django-query-log.svg)](https://pypi.org/project/django-query-log/)\n[![Django Support](https://img.shields.io/badge/django-3.2%2B-brightgreen.svg)](https://www.djangoproject.com/)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\nA comprehensive Django package for logging database query execution time and performance analysis for all Django requests. Monitor your application's database performance with detailed insights, N+1 query detection, and customizable logging formats. Works with regular Django views, class-based views, and Django REST Framework APIs.\n\n## Features\n\n- \ud83d\ude80 **Real-time Query Monitoring**: Track database queries for all Django requests\n- \ud83d\udcca **Performance Analysis**: Automatic detection of slow queries and performance bottlenecks\n- \ud83d\udd0d **N+1 Query Detection**: Identify and warn about N+1 query problems\n- \ud83d\udd04 **Duplicate Query Detection**: Find and report duplicate queries\n- \ud83d\udcdd **Multiple Log Formats**: Support for JSON, compact, detailed, and custom formatters\n- \u2699\ufe0f **Highly Configurable**: Extensive configuration options for different use cases\n- \ud83c\udfaf **Universal Django Support**: Works with function views, class-based views, and Django REST Framework\n- \ud83d\udd10 **Security**: Automatic sanitization of sensitive data in logs\n- \ud83d\udcc8 **Stack Trace Support**: Optional stack trace logging for query sources\n- \ud83c\udfa8 **Custom Formatters**: Create your own log formatting logic\n\n## Installation\n\nInstall using pip:\n\n```bash\npip install django-query-log\n```\n\nFor Django REST Framework support:\n\n```bash\npip install django-query-log[drf]\n```\n\nOr install with development dependencies:\n\n```bash\npip install django-query-log[dev]\n```\n\n## Quick Start\n\n1. **Add to Django Settings**:\n\n```python\n# settings.py\nINSTALLED_APPS = [\n    # ... your other apps\n    'django_query_log',\n]\n\nMIDDLEWARE = [\n    # ... your other middleware\n    'django_query_log.middleware.QueryLogMiddleware',\n    # ... rest of your middleware\n]\n\n# Optional: Configure django-query-log\nDJANGO_QUERY_LOG = {\n    'ENABLED': True,\n    'LOG_LEVEL': 'INFO',\n    'LOGGER_NAME': 'django_query_log',\n}\n```\n\n2. **Configure Logging** (optional):\n\n```python\n# settings.py\nLOGGING = {\n    'version': 1,\n    'disable_existing_loggers': False,\n    'handlers': {\n        'query_log': {\n            'level': 'INFO',\n            'class': 'logging.StreamHandler',\n            'formatter': 'verbose',\n        },\n    },\n    'loggers': {\n        'django_query_log': {\n            'handlers': ['query_log'],\n            'level': 'INFO',\n            'propagate': False,\n        },\n    },\n    'formatters': {\n        'verbose': {\n            'format': '{levelname} {asctime} {module} {message}',\n            'style': '{',\n        },\n    },\n}\n```\n\n3. **Start your Django server** and make requests to any Django view. Query logs will appear in your console!\n\n## Usage Examples\n\n### Basic Usage\n\nOnce installed and configured, django-query-log automatically logs database queries for all Django requests (views, APIs, admin, etc.):\n\n```\n[2024-01-15T10:30:45.123456] GET /api/users/ - Queries: 3, Total Time: 0.0157s\n  User: admin (ID: 1)\n  Performance Analysis:\n    Average Query Time: 0.0052s\n    Duplicate Queries: 0 queries in 0 groups\n  Queries:\n    1. [0.0031s] SELECT \"auth_user\".\"id\", \"auth_user\".\"username\", \"auth_user\".\"email\" FROM \"auth_user\" WHERE \"auth_user\".\"is_active\" = TRUE\n    2. [0.0089s] SELECT \"user_profile\".\"id\", \"user_profile\".\"user_id\", \"user_profile\".\"avatar\" FROM \"user_profile\" WHERE \"user_profile\".\"user_id\" IN (1, 2, 3)\n    3. [0.0037s] SELECT COUNT(*) AS \"__count\" FROM \"auth_user\" WHERE \"auth_user\".\"is_active\" = TRUE\n  Response: 200 (1024 bytes)\n```\n\n### Using Different Formatters\n\n**JSON Formatter** (great for structured logging):\n\n```python\n# settings.py\nDJANGO_QUERY_LOG = {\n    'FORMATTER_CLASS': 'django_query_log.formatters.JSONFormatter',\n}\n```\n\n**Compact Formatter** (minimal output):\n\n```python\n# settings.py\nDJANGO_QUERY_LOG = {\n    'FORMATTER_CLASS': 'django_query_log.formatters.CompactFormatter',\n}\n```\n\nOutput:\n\n```\n[2024-01-15T10:30:45.123456] GET /api/users/ | queries=3 | time=0.016s | user=admin\n```\n\n**Detailed Formatter** (comprehensive information):\n\n```python\n# settings.py\nDJANGO_QUERY_LOG = {\n    'FORMATTER_CLASS': 'django_query_log.formatters.DetailedFormatter',\n}\n```\n\n### Works with All Django Views\n\nDjango Query Log works seamlessly with all types of Django views:\n\n**Function-based views:**\n\n```python\ndef my_view(request):\n    users = User.objects.all()  # Logged automatically\n    return render(request, 'users.html', {'users': users})\n```\n\n**Class-based views:**\n\n```python\nclass UserListView(ListView):\n    model = User  # All queries logged automatically\n    template_name = 'users.html'\n```\n\n**Django REST Framework views:**\n\n```python\nfrom rest_framework.viewsets import ModelViewSet\n\nclass UserViewSet(ModelViewSet):\n    queryset = User.objects.all()  # All queries logged automatically\n    serializer_class = UserSerializer\n```\n\n### Context Manager\n\nTemporarily disable or enable logging for specific code blocks:\n\n```python\nfrom django_query_log.middleware import DjangoQueryLogContext\n\n# Disable logging for this block\nwith DjangoQueryLogContext(enabled=False):\n    users = User.objects.all()  # This won't be logged\n\n# Enable logging (if disabled globally)\nwith DjangoQueryLogContext(enabled=True):\n    users = User.objects.all()  # This will be logged\n```\n\n## Configuration\n\n### Complete Configuration Options\n\n```python\n# settings.py\nDJANGO_QUERY_LOG = {\n    # Enable/disable query logging\n    'ENABLED': True,\n\n    # Minimum query execution time to log (in seconds)\n    'MIN_QUERY_TIME': 0.001,\n\n    # Maximum number of queries to log per request\n    'MAX_QUERIES_PER_REQUEST': 100,\n\n    # Log level for query information\n    'LOG_LEVEL': 'INFO',  # DEBUG, INFO, WARNING, ERROR, CRITICAL\n\n    # Logger name to use\n    'LOGGER_NAME': 'django_query_log',\n\n    # Include request information in logs\n    'INCLUDE_REQUEST_INFO': True,\n\n    # Include response information in logs\n    'INCLUDE_RESPONSE_INFO': True,\n\n    # Include user information in logs\n    'INCLUDE_USER_INFO': True,\n\n    # Include SQL query text in logs\n    'INCLUDE_SQL': True,\n\n    # Include query execution stack trace\n    'INCLUDE_STACK_TRACE': False,\n\n    # Sensitive parameters to exclude from logs\n    'SENSITIVE_PARAMS': ['password', 'token', 'secret', 'key'],\n\n    # Only log queries for specific paths (empty list means all paths)\n    'INCLUDE_PATHS': [],\n\n    # Exclude queries for specific paths\n    'EXCLUDE_PATHS': ['/admin/', '/static/', '/media/'],\n\n    # Custom formatter class\n    'FORMATTER_CLASS': 'django_query_log.formatters.DefaultFormatter',\n\n    # Include duplicate query detection\n    'DETECT_DUPLICATE_QUERIES': True,\n\n    # Warn about N+1 query problems\n    'DETECT_N_PLUS_ONE': True,\n\n    # Include query performance analysis\n    'INCLUDE_PERFORMANCE_ANALYSIS': True,\n}\n```\n\n### Configuration Examples\n\n**Production Environment** (minimal logging):\n\n```python\nDJANGO_QUERY_LOG = {\n    'ENABLED': True,\n    'MIN_QUERY_TIME': 0.01,  # Only log slow queries\n    'MAX_QUERIES_PER_REQUEST': 50,\n    'LOG_LEVEL': 'WARNING',\n    'INCLUDE_SQL': False,  # Don't log SQL in production\n    'FORMATTER_CLASS': 'django_query_log.formatters.CompactFormatter',\n    'EXCLUDE_PATHS': ['/admin/', '/static/', '/media/', '/health/'],\n}\n```\n\n**Development Environment** (detailed logging):\n\n```python\nDJANGO_QUERY_LOG = {\n    'ENABLED': True,\n    'MIN_QUERY_TIME': 0.001,\n    'LOG_LEVEL': 'DEBUG',\n    'INCLUDE_STACK_TRACE': True,\n    'FORMATTER_CLASS': 'django_query_log.formatters.DetailedFormatter',\n    'DETECT_N_PLUS_ONE': True,\n    'DETECT_DUPLICATE_QUERIES': True,\n}\n```\n\n**API-Only Logging**:\n\n```python\nDJANGO_QUERY_LOG = {\n    'ENABLED': True,\n    'INCLUDE_PATHS': ['/api/'],  # Only log API requests\n    'EXCLUDE_PATHS': ['/api/health/', '/api/metrics/'],\n}\n```\n\n## Performance Features\n\n### N+1 Query Detection\n\nDjango Query Log automatically detects potential N+1 query problems:\n\n```\nN+1 Query Issues: 1 detected\n  - Pattern executed 25 times (0.1234s total)\n```\n\n### Duplicate Query Detection\n\nIdentifies repeated identical queries:\n\n```\nDuplicate Queries: 15 queries in 3 groups\n```\n\n### Slow Query Identification\n\nHighlights the slowest queries in each request:\n\n```\nSlowest Queries:\n  1. [0.0892s] SELECT * FROM \"products\" WHERE \"products\".\"category_id\" = 1\n  2. [0.0445s] SELECT COUNT(*) FROM \"orders\" WHERE \"orders\".\"user_id\" = 123\n```\n\n## Custom Formatters\n\nCreate your own custom formatter:\n\n```python\n# myapp/formatters.py\nfrom django_query_log.formatters import BaseFormatter\n\nclass MyCustomFormatter(BaseFormatter):\n    def format_log_entry(self, log_data):\n        request_info = log_data.get('request', {})\n        performance = log_data.get('performance_analysis', {})\n\n        return f\"API {request_info.get('method')} {request_info.get('path')} \" \\\n               f\"executed {performance.get('total_queries', 0)} queries \" \\\n               f\"in {performance.get('total_time', 0):.3f}s\"\n\n# settings.py\nDJANGO_QUERY_LOG = {\n    'FORMATTER_CLASS': 'myapp.formatters.MyCustomFormatter',\n}\n```\n\n## Integration with Logging Systems\n\n### Structured Logging with JSON\n\n```python\nimport json\nimport logging\n\nclass JSONLogHandler(logging.StreamHandler):\n    def emit(self, record):\n        try:\n            # Parse the log message as JSON if possible\n            log_data = json.loads(record.getMessage())\n            # Send to your logging service (e.g., ELK, Splunk, etc.)\n            super().emit(record)\n        except json.JSONDecodeError:\n            super().emit(record)\n\n# settings.py\nLOGGING = {\n    'handlers': {\n        'json_query_log': {\n            'level': 'INFO',\n            '()': 'myapp.logging.JSONLogHandler',\n        },\n    },\n    'loggers': {\n        'django_query_log': {\n            'handlers': ['json_query_log'],\n            'level': 'INFO',\n        },\n    },\n}\n\nDJANGO_QUERY_LOG = {\n    'FORMATTER_CLASS': 'django_query_log.formatters.JSONFormatter',\n}\n```\n\n## Requirements\n\n- Python 3.8+\n- Django 3.2+\n- Django REST Framework 3.12.0+ (optional)\n\n## Compatibility\n\n- **Django**: 3.2, 4.0, 4.1, 4.2, 5.0\n- **Python**: 3.8, 3.9, 3.10, 3.11, 3.12\n- **Django REST Framework**: 3.12.0+ (optional for API logging)\n\n## Contributing\n\nWe welcome contributions! Please see our [Contributing Guidelines](CONTRIBUTING.md) for details.\n\n### Development Setup\n\n1. Clone the repository:\n\n```bash\ngit clone https://github.com/dipee/django-query-log.git\ncd django-query-log\n```\n\n2. Install development dependencies:\n\n```bash\npip install -e .[dev]\n```\n\n3. Run tests:\n\n```bash\npytest\n```\n\n4. Run linting:\n\n```bash\nblack .\nflake8 .\nisort .\nmypy .\n```\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n## Changelog\n\nSee [CHANGELOG.md](CHANGELOG.md) for release history.\n\n## Support\n\n- **Documentation**: [https://django-query-log.readthedocs.io/](https://django-query-log.readthedocs.io/)\n- **Issues**: [https://github.com/dipee/django-query-log/issues](https://github.com/dipee/django-query-log/issues)\n- **Discussions**: [https://github.com/dipee/django-query-log/discussions](https://github.com/dipee/django-query-log/discussions)\n\n## Acknowledgments\n\n- Inspired by Django Debug Toolbar's query logging capabilities\n- Built for Django developers who need production-ready query monitoring for all types of views\n- Thanks to all contributors who help improve this package\n\n---\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A Django package for logging database query execution time and performance analysis for all Django requests",
    "version": "1.0.0",
    "project_urls": {
        "Bug Tracker": "https://github.com/dipendra-sharma/django-query-log/issues",
        "Changelog": "https://github.com/dipendra-sharma/django-query-log/blob/main/CHANGELOG.md",
        "Documentation": "https://django-query-log.readthedocs.io/",
        "Homepage": "https://github.com/dipendra-sharma/django-query-log",
        "Source Code": "https://github.com/dipendra-sharma/django-query-log"
    },
    "split_keywords": [
        "django",
        " database",
        " query",
        " logging",
        " performance",
        " monitoring",
        " sql",
        " middleware",
        " n+1",
        " optimization",
        " inspector",
        " debugging"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "989fa646ec6cfa4e4ee79531c5b485a2493a0538c4c68e859a1e05d851caae6e",
                "md5": "0db53b8f4b5bd71a3c83cd5d4c897e0f",
                "sha256": "39a642b680fea9727aac7fa24b41ff1d170d9fa2f12bde63a7d70a53157267a0"
            },
            "downloads": -1,
            "filename": "django_query_log-1.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "0db53b8f4b5bd71a3c83cd5d4c897e0f",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 16106,
            "upload_time": "2025-07-19T08:37:44",
            "upload_time_iso_8601": "2025-07-19T08:37:44.770916Z",
            "url": "https://files.pythonhosted.org/packages/98/9f/a646ec6cfa4e4ee79531c5b485a2493a0538c4c68e859a1e05d851caae6e/django_query_log-1.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "cf1b1158e33929902ac29b76c4ca03017e9ee8eb2b78abb8c2f4a632989de305",
                "md5": "0dd0a41699df77bee60e67813d811225",
                "sha256": "e8f28687e2270c0b49f15431086ce722b7881479404bc5e5e153f0a808ecfaee"
            },
            "downloads": -1,
            "filename": "django_query_log-1.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "0dd0a41699df77bee60e67813d811225",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 20422,
            "upload_time": "2025-07-19T08:37:46",
            "upload_time_iso_8601": "2025-07-19T08:37:46.260901Z",
            "url": "https://files.pythonhosted.org/packages/cf/1b/1158e33929902ac29b76c4ca03017e9ee8eb2b78abb8c2f4a632989de305/django_query_log-1.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-07-19 08:37:46",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "dipee",
    "github_project": "django-query-log",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [
        {
            "name": "Django",
            "specs": [
                [
                    ">=",
                    "3.2"
                ]
            ]
        }
    ],
    "lcname": "django-query-log"
}
        
Elapsed time: 1.19366s