Jestem obecnie zalogowaniu wszystkie zapytań SQL dzięki następujących ustawień rejestrowania:Django filtr dziennika powolnego zapytań SQL
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'filters': {
'require_debug_false': {
'()': 'django.utils.log.RequireDebugFalse'
}
},
'formatters': {
'standard': {
'format' : "[%(asctime)s] %(levelname)s [%(name)s:%(lineno)s] %(message)s",
'datefmt' : "%d/%b/%Y %H:%M:%S"
},
},
'handlers': {
'mail_admins': {
'level': 'ERROR',
'filters': ['require_debug_false'],
'class': 'django.utils.log.AdminEmailHandler'
},
'console': {
# logging handler that outputs log messages to terminal
'class': 'logging.StreamHandler',
'level': 'DEBUG', # message level to be written to console
},
'logfile': {
'level':'DEBUG',
'class':'logging.handlers.RotatingFileHandler',
'filename': os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "log", "logfile"),
'maxBytes': 50000,
'backupCount': 2,
'formatter': 'standard',
},
},
'loggers': {
'django.request': {
'handlers': ['mail_admins'],
'level': 'ERROR',
'propagate': True,
},
'django.db': {
'handlers': ['logfile'],
'level': 'DEBUG',
'propagate': False, # django also has database level logging
},
}
}
Co tak naprawdę się w moim dzienniku jest:
[14/Jun/2013 13:54:19] DEBUG [django.db.backends:51] (0.000) SELECT "django_content_type"."id", "django_content_type"."name", "django_content_type"."app_label", "django_content_type"."model" FROM "django_content_type" WHERE "django_content_type"."app_label" = sites ORDER BY "django_content_type"."name" ASC; args=(u'sites',)
ja lubię filtrować tylko zapytania, które trwają ponad 300 ms.
Jak mam napisać sekcję filters
mojej konfiguracji logowania i jaka będzie wyglądała klasa, która wykonuje filtrowanie?
Jest to bardzo pomocne! Jedyną modyfikacją, którą wprowadziłem, było [ustawienie filtru w loggerze] (https://docs.python.org/2/library/logging.html#filter-objects) ({{'django.db.backends'}} w mój przypadek) zamiast na treserze. – tutuDajuju
Czy istnieje również sposób na zbudowanie stosu stacktrace? więc wiemy, gdzie pojawiło się zapytanie? –