Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Log django database queries using logging

Tags:

logging

django

I want to log insert, update, delete and failed select query in my daily log file. I configured django.db.backends in the logger of the Logging dict in settings.py. But I get all the queries in that application. I need only insert, update, delete and failed select queries.

like image 809
Anju Avatar asked Mar 13 '14 07:03

Anju


1 Answers

Try to add this to you settings.py.

LOGGING = {
    'version': 1,
    'handlers': {
        'file': {
            'level': 'DEBUG',
            'class': 'logging.FileHandler',
            'filename': '/path/to/django/debug.log',
        },
    },
    'loggers': {
        'django.db.backends': {
            'handlers': ['file'],
            'level': 'DEBUG',
        },
    },
}

The documentation may help you and this article too.

like image 142
gustavi Avatar answered Nov 14 '22 22:11

gustavi