The following is the logging configuration for our Django application
logging.config.dictConfig({
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'verbose': {
'format': '%(asctime)s %(name)-12s %(lineno)d %(module)s %(levelname)-8s %(message)s'
},
'simple': {
'format': '%(levelname)s %(message)s'
},
},
'filters': {
'require_debug_false': {
'()': 'django.utils.log.RequireDebugFalse'
}
},
'handlers': {
'console': {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
'formatter': 'simple'
},
'file': {
'level': 'DEBUG',
'class': 'logging.handlers.RotatingFileHandler',
'maxBytes': 15728640, # 100MB
'backupCount': 10,
'formatter': 'verbose',
'filename': 'log_files/acme-slcms.log',
'encoding': 'utf-8',
},
'mail_admins': {
'level': 'CRITICAL',
'filters': ['require_debug_false'],
'class': 'django.utils.log.AdminEmailHandler'
},
},
'loggers': {
'django': {
'propagate': True,
'level': 'DEBUG',
'handlers': ['file'],
},
'django.db.backends': {
'propagate': False,
'level': 'DEBUG',
'handlers': ['file'],
}
}
})
We have added the django.db.backends logger to print the queries generated by the application. But from the output, it seems the logger is connecting to the public schema
2021-10-06 13:37:39,704 django.db.backends 123 utils DEBUG (0.089)
SELECT c.relname, c.relkind
FROM pg_catalog.pg_class c
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
WHERE c.relkind IN ('r', 'v', '')
AND n.nspname = 'public'
AND pg_catalog.pg_table_is_visible(c.oid); args=None
After adding the log configuration, we are not seeing any queries other than this.
The application is actually using another schema for storing and retrieving data and is using django-tenant as part of the homegrown framework.
Note
We can see the line 2021-10-06 09:39:58,096 django.utils.autoreload 368 autoreload DEBUG is being printed continuously.
Eg: 2021-10-06 09:39:58,096 django.utils.autoreload 368 autoreload DEBUG File /home/foo/Desktop/bar/my_env/lib/python3.8/site-packages/fido2/attestation/android.py first seen with mtime 1612337859.0