There is any posibility to see raw sql when DEBUG=True and DEBUG=False? And for methods delete() and save()? I want to log all requests for my app, and I don't understand how I can log raw sql.
Asked
Active
Viewed 1,000 times
1 Answers
2
Make sure you read docs on logging.
You need the django.db.backends
logger and RequireDebugFalse
filter.
Example settings:
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'filters': {
'require_debug_false': {
'()': 'django.utils.log.RequireDebugFalse'
}
},
'handlers': {
'console':{
'level':'DEBUG',
'filters': ['require_debug_false'],
'class':'logging.StreamHandler',
},
},
'loggers': {
'django.db.backends': {
'handlers':['console'],
'propagate': True,
'level':'DEBUG',
},
}
}
Note: you can also enable SQL query logging in the SQL server configuration, without touching django. Refer to your SQL server documentation for details.

jpic
- 32,891
- 5
- 112
- 113
-
It looks like I miss somethig( I added your code to settings.py, added `import logging; l= logging.getLogger('django.db.backends'); l.setLevel(logging.DEBUG); l.addHandler(logging.StreamHandler())` to views.py, I can see log messages in console, but I don't understand how to see an sql... – Ishayahu Jul 07 '13 at 10:38
-
With `Debug=False` it doesn't work, with `Debug=True` - works. It looks like with DEBUG=False it can't work: `For performance reasons, SQL logging is only enabled when settings.DEBUG is set to True, regardless of the logging level or handlers that are installed.` – Ishayahu Jul 07 '13 at 11:20
-