How can I log all SQL queries that my django application performed?
I want to log everything, including SQLs from admin site. I saw this question and a FAQ answer but I still can't figure out where should I put
from django.db import connection connection.queries
to log everything to one file?
So my question is - what should I do to have a file (say all-sql.log) where all SQL statements are logged?
By default, SQL Server activity is not logged the way you expect. Some write activity is recorded in the Transaction Log, but this also depends on how your databases are set up.
Merge the following snippet with the LOGGING
field in your settings.py
:
LOGGING = { 'version': 1, 'filters': { 'require_debug_true': { '()': 'django.utils.log.RequireDebugTrue', } }, 'handlers': { 'console': { 'level': 'DEBUG', 'filters': ['require_debug_true'], 'class': 'logging.StreamHandler', } }, 'loggers': { 'django.db.backends': { 'level': 'DEBUG', 'handlers': ['console'], } } }
Tweaked from @acardenas89 answer
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With