Skip to content

Instantly share code, notes, and snippets.

@axeliodiaz
Last active December 23, 2016 15:31
Show Gist options
  • Save axeliodiaz/04a493e7d414644c78b800e68255d4af to your computer and use it in GitHub Desktop.
Save axeliodiaz/04a493e7d414644c78b800e68255d4af to your computer and use it in GitHub Desktop.
Logger config to save SQL trace in a file log
DEBUG = True
LOGGING = {
'version': 1,
'disable_existing_loggers': True,
'formatters': {
'standard': {
'format': "%(sql)s",
},
},
'handlers': {
'null': {
'level': 'DEBUG',
'class': 'django.utils.log.NullHandler',
},
'logfile': {
'level': 'DEBUG',
'class': 'logging.handlers.RotatingFileHandler',
'filename': BASE_DIR + "/log_sql.sql",
'maxBytes': 50000,
'backupCount': 2,
'formatter': 'standard',
},
'console': {
'level': 'INFO',
'class': 'logging.StreamHandler',
'formatter': 'standard'
},
},
'loggers': {
'django': {
'handlers': ['console'],
'propagate': True,
'level': 'WARN',
},
'django.db.backends': {
'handlers': ['console', 'logfile'],
'filename': BASE_DIR + "/log_sql.sql",
'level': 'DEBUG',
'propagate': False,
},
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment