Ishayahu
Ishayahu

Reputation: 355

Show raw SQL in Django with DEBUG=True & for delete() and save()

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.

Upvotes: 2

Views: 1107

Answers (1)

jpic
jpic

Reputation: 33420

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.

Upvotes: 2

Related Questions