Skip to content

Commit

Permalink
Merge pull request #9 from wkeeling/allow-logging-integers
Browse files Browse the repository at this point in the history
Allow non-string messages to be concatenated
  • Loading branch information
wkeeling authored Apr 1, 2019
2 parents 5258925 + 859023c commit a686cbc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
7 changes: 5 additions & 2 deletions ratelimitingfilter/ratelimitingfilter.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,11 @@ def filter(self, record):
if bucket.consume():
if bucket.limited > 0:
# Append a message to the record indicating the number of previously suppressed messages
record.msg += '{linesep}... {num} additional messages suppressed'.format(linesep=os.linesep,
num=bucket.limited)
record.msg = '{msg}{linesep}... {num} additional messages suppressed'.format(
msg=record.msg,
linesep=os.linesep,
num=bucket.limited
)
bucket.limited = 0
return True

Expand Down
12 changes: 9 additions & 3 deletions tests/ratelimitingfilter_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,19 @@ def test_limit_to_two_record_per_ten_second(self):

self.assertEqual(result.count(True), 2)

def test_rate_limit_non_string(self):
f = RateLimitingFilter(rate=2, per=10)

result = self._filter_r_records_over_s_seconds(f, 20, 10, message=123)

self.assertEqual(result.count(True), 2)

def _filter_twenty_records_over_two_seconds(self, f):
return self._filter_r_records_over_s_seconds(f, 20, 2)


def _filter_r_records_over_s_seconds(self, f, nb_records, nb_seconds):
def _filter_r_records_over_s_seconds(self, f, nb_records, nb_seconds, message='test message'):
mock_record = Mock()
mock_record.msg = 'test message'
mock_record.msg = message

result = []

Expand Down

0 comments on commit a686cbc

Please sign in to comment.