Reputation: 317
I'm trying to log my database queries using Django Logging, but the log message seems to be void. I'm using Django 2.1, Python 3.6, with MySQL database.
My settings.py
:
LOGGING = {
'version': 1,
'formatters': {
'standard': {
'format': '%(asctime)s [%(levelname)s] %(name)s: %(message)s'
},
},
'handlers': {
'default': {
'level':'DEBUG',
'class':'logging.handlers.RotatingFileHandler',
'filename': SITE_ROOT + '/mylog.log',
'maxBytes': 1024*1024*5, # 5 MB
'backupCount': 5,
'formatter':'standard',
},
},
'loggers': {
'django.db.backends': {
'handlers': ['default'],
'level': 'DEBUG',
'propagate': True
},
}
}
Resulting log:
2019-02-07 11:27:17,642 [DEBUG] django.db.backends: (0.000) None; args=None
2019-02-07 11:27:17,642 [DEBUG] django.db.backends: (0.000) None; args=None
2019-02-07 11:27:17,643 [DEBUG] django.db.backends: (0.000) None; args=(2,)
2019-02-07 11:27:17,657 [DEBUG] django.db.backends: (0.000) None; args=(2,)
2019-02-07 11:27:17,670 [DEBUG] django.db.backends: (0.000) None; args=(2,)
2019-02-07 11:27:17,843 [DEBUG] django.db.backends: (0.165) None; args=(2, 2, 2)
How can I have the SQL queries?
Upvotes: 1
Views: 1079
Reputation: 479
This bug is fixed already. Upgrade your Django. See https://github.com/django/django/pull/10726
Upvotes: 0
Reputation: 41
I encountered the same issue.
It's definitely a problem with mysqlclient.
I was using django 1.11.6 Which is an old «patch» version.
I just tried to upgrade django with the latest 1.11.x, the 1.11.29 and the bug is here as well
So upgrading Django doesn't fix the bug, it isn't fixed in 1.11.x branch of django
the version 1.4.6 of mysqlclient is the last version that doesn't have the issue, on both 1.11.6 and 1.11.29
I created the issue https://github.com/PyMySQL/mysqlclient-python/issues/441
Upvotes: 0
Reputation: 305
Slightly late to the party, but I just ran into this issue and found a resolution on django-debug-toolbar's GitHub page about this specific issue. Apparently mysqlclient==1.3.14
might be the culprit, and using a different version of it (I tried 1.3.12 and 1.4.4) solved this problem for me.
Upvotes: 3