Write Django's SQL statements to a JSONL log file
Project description
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 toTrue
- SQLLOG_PATH_RE a regex pattern to only log SQL queries in hte 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 toFalse
- SQLLOG_LOG_META log
request.META
data. Defaults toFalse
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
File details
Details for the file django_sql_log_middleware-0.1.6-py3-none-any.whl
.
File metadata
- Download URL: django_sql_log_middleware-0.1.6-py3-none-any.whl
- Upload date:
- Size: 4.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.9.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7d6a08eed82b831bf56042b0600a84ed991b4326b3b9c772292394054469b6c5 |
|
MD5 | b42679d0324c553c1b97230457be329d |
|
BLAKE2b-256 | 0e3f7314a2e8e04497ef86f257f7ec172462902e86e24f2722fe4fca0af89c75 |