Login

Log the time taken to execute each DB query

Author:
kennyx46
Posted:
March 24, 2021
Language:
Python
Version:
Not specified
Tags:
django db logging
Score:
1 (after 1 ratings)

Use this snippet to log the time taken to execute a specific DB query.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# 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'],
        }
    }
}

More like this

  1. "Magic Link" Management Command by webology 1 month, 3 weeks ago
  2. Closest ORM models to a latitude/longitude point by simonw 1 month, 3 weeks ago
  3. Log the time taken to execute each DB query by kennyx46 1 month, 3 weeks ago
  4. django database snippet by ItsRLuo 2 months ago
  5. Serialize a model instance by chriswedgwood 2 months, 4 weeks ago

Comments

Please login first before commenting.