Last active
December 2, 2022 04:20
-
-
Save morenoh149/033ee3f7005cd6099d2fb4a114cffd34 to your computer and use it in GitHub Desktop.
Django log slow queries
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
LOGGING = { | |
'version': 1, | |
'disable_existing_loggers': False, | |
'filters': { | |
'slow_queries': { | |
'()': 'django.utils.log.CallbackFilter', | |
# output slow queries only, unit are 1s, so 0.3 is 300ms | |
# ref 300ms * 0.001 = 0.3, 50ms * 0.001 = 0.05 | |
'callback': lambda record: record.duration > 0.05 | |
}, | |
}, | |
'handlers': { | |
'console': { | |
'class': 'logging.StreamHandler', | |
}, | |
}, | |
'loggers': { | |
'django': { | |
'handlers': ['console'], | |
'level': 'DEBUG', | |
'propagate': True, | |
}, | |
'django.db.backends': { | |
'handlers': ['console'], | |
'level': 'DEBUG', | |
'propagate': False, | |
'filters': ['slow_queries'], | |
}, | |
}, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment