djangologgingdjango-logging

Django Logging - How to remove SQL query in logging file


I try to make Django Logging to log error from server. Now my code:

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'handlers': {
        'file': {
            'level': 'DEBUG',
            'class': 'logging.FileHandler',
            'filename': os.path.join(PROJECT_LOCAL_URL, 'mylog.log'),
        },
    },
    'loggers': {
        'django': {
            'handlers': ['file'],
            'level': 'DEBUG',
            'propagate': True,
        },
    },
}

When I check mylog.log, it have too many sql queries string - SELECT FROM, which I want not to see. How can I config this?

enter image description here

How can I remove all sql queries in logging file?


Solution

  • Database queries are logged by a django.db.backends logger. Assuming you still want DEBUG level logging everywhere else then you need to specifically define a rule for this logger to ignore DEBUG logging:

    'loggers': {
        'django': {
            'handlers': ['file'],
            'level': 'DEBUG',
            'propagate': True,
        },
        'django.db.backends': {
            'handlers': ['file'],
            'level': 'WARNING',   # DEBUG will log all queries, so change it to WARNING.
            'propagate': False,   # Don't propagate to other handlers
        },
    },