Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

log all sql queries

Tags:

django

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?

like image 780
Oleg Pavliv Avatar asked Dec 07 '10 10:12

Oleg Pavliv


People also ask

Are SQL queries 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.


1 Answers

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

like image 200
Gian Marco Avatar answered Sep 29 '22 08:09

Gian Marco