To comprehensively log all SQL queries executed by a Django application, including those generated by the admin site, follow these steps:
<code class="python">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'], } } }</code>
<code class="python">'handlers': { 'file': { 'level': 'DEBUG', 'filters': ['require_debug_true'], 'class': 'logging.FileHandler', 'filename': 'all-sql.log', } },</code>
With this configuration, all SQL queries executed by your Django application will now be logged to the specified file ('all-sql.log' in this example). This provides a convenient way to troubleshoot database-related issues or perform auditing.
Ce qui précède est le contenu détaillé de. pour plus d'informations, suivez d'autres articles connexes sur le site Web de PHP en chinois!