Skip to content

Commit

Permalink
strip duplicate ARGS info in sql logging
Browse files Browse the repository at this point in the history
closes #9
  • Loading branch information
crccheck committed Jan 24, 2015
1 parent 198bae1 commit 5d196fa
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
6 changes: 5 additions & 1 deletion project_runpy/heidi.py
Expand Up @@ -133,6 +133,10 @@ def filter(self, record):
end = record.msg.index('FROM')
except ValueError: # not all SELECT statements also have a FROM
return True
try:
very_end = record.msg.rindex(u'; args') + 1
except ValueError: # msg does not have "args" to strip
very_end = None
record.msg = u'{0} ... {1}'.format(
record.msg[:begin + 6], record.msg[end:])
record.msg[:begin + 6], record.msg[end:very_end])
return True
20 changes: 20 additions & 0 deletions test_project_runpy.py
Expand Up @@ -185,6 +185,26 @@ def test_filter_formats_select_from_dj17(self):
self.assertTrue(logging_filter.filter(record))
self.assertNotIn(VERY_LONG_STRING, record.msg)

def test_filter_removes_args(self):
sql = u"""SELECT ... FROM "tx_lobbying_expensedetailreport" GROUP BY "tx_lobbying_expensedetailreport"."year", "tx_lobbying_expensedetailreport"."type" ORDER BY "tx_lobbying_expensedetailreport"."year" ASC; args=()"""
logging_filter = ReadableSqlFilter()
record = type('mock_record', (object, ), {
'sql': sql,
'msg': u'(yolo) {0}'.format(sql),
})
self.assertTrue(logging_filter.filter(record))
self.assertNotIn('; args=()', record.msg)

# assert it also works when there's no args to begin with
sql = u"""SELECT ... FROM "tx_lobbying_expensedetailreport" GROUP BY "tx_lobbying_expensedetailreport"."year", "tx_lobbying_expensedetailreport"."type" ORDER BY "tx_lobbying_expensedetailreport"."year" ASC"""
logging_filter = ReadableSqlFilter()
record = type('mock_record', (object, ), {
'sql': sql,
'msg': u'(yolo) {0}'.format(sql),
})
self.assertTrue(logging_filter.filter(record))
self.assertNotIn('; args=()', record.msg)


if __name__ == '__main__':
unittest.main()

0 comments on commit 5d196fa

Please sign in to comment.