Skip to main content

Django SQL Log Middleware

A middleware to write Django SQL queries and stats to a jsonl file. Makes analysis easier when you have log files that are hundreds of megabytes.

Inspired by the django-sqlprint-middleware project

Installation

pip install django-sql-log-middleware

Add it to the middleware section of settings.py:

MIDDLEWARE = [
    ...
    'django_sql_log_middleware.SqlLogMiddleware',
]

Output

Output will be written to the path specified in SQLLOG_LOG in the below format. Each line is a JSON object covering a single request. Time is the current unix time. Query time is measured in seconds.

{
        "path": "/path/to/api?abc=1234",
        "time": 1649301150,
        "queries": [
            {"sql": "select * from users", "time": 1.1234},
            {"sql": "select * from things", "time": 4.1234},
        ]
}

Settings

Specify the following settings in your settings.py file:

  • DEBUG This middleware will only run when DEBUG is set.
  • SQLLOG_MIDDLEWARE set this variable to False disable the middleware without removal. Defaults to True
  • SQLLOG_PATH_RE a regex pattern to only log SQL queries in the matched path(s). Defaults to .*
  • SQLLOG_LOG the file to write out the logs to. Defaults to django_queries.jsonl
  • SQLLOG_LOG_POST log request.POST data. Defaults to False
  • SQLLOG_LOG_META log request.META data. Defaults to False

Any outputs that can't be JSON serialized will be rendered as <not serializable>

Metadata

Release files for django-sql-log-middleware 0.1.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-sql-log-middleware 0.1.8
File Size Uploaded Provenance
django-sql-log-middleware-0.1.8.tar.gz 3.7 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for django-sql-log-middleware 0.1.8
File Interpreter ABI Platform
django_sql_log_middleware-0.1.8-py3-none-any.whl Python 3 none any Details

Total release size: 8.1 kB

Release files / django-sql-log-middleware-0.1.8.tar.gz

Download URL django-sql-log-middleware-0.1.8.tar.gz
Size 3.7 kB
Tags Source
SHA-256 checksum
How to use checksums
0acaed1027e1392fe7bca998dd2b922e432c060fac62ec5b48a5f0a50510e578
BLAKE2b-256 checksum
How to use checksums
7640b51f2ccbcb1415a755031871ccbe30da6fdef210927c4a542a8553ee2894
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.9.10

Release files / django_sql_log_middleware-0.1.8-py3-none-any.whl

Download URL django_sql_log_middleware-0.1.8-py3-none-any.whl
Size 4.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
95a05c1243b6e28caf1941b32c37ee1187743f190f0ed159ad4c2cc59ea6c9b1
BLAKE2b-256 checksum
How to use checksums
7687841571c0d4df261ca3a6a47cb0bb76edaef56cdc80c7d01484985748363d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.9.10

Security for django-sql-log-middleware 0.1.8

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page