我發現了一個似乎暫時工作的黑客。在Django/DB /後端/ util.py:
class CursorDebugWrapper(CursorWrapper):
# XXX callproc isn't instrumented at this time.
def execute(self, sql, params=None):
start = time()
try:
return super(CursorDebugWrapper, self).execute(sql, params)
finally:
stop = time()
duration = stop - start
sql = self.db.ops.last_executed_query(self.cursor, sql, params)
self.db.queries.append({
'sql': sql,
'time': "%.3f" % duration,
})
logger.debug('(%.3f) %s; args=%s' % (duration, sql, params),
extra={'duration': duration, 'sql': sql, 'params': params}
)
我改變最後一行:
logger.debug('(%.3f) %s; args=%s' % (duration, sql.decode('utf-8'), params),
extra={'duration': duration, 'sql': sql, 'params': params}
)
將是巨大的,如果有人可以提供更好/更優雅的解決方案。
來源
2014-04-03 08:55:27
RVC
如何使用自定義記錄器類?請參閱:http://stackoverflow.com/a/44009835/3015186 – np8