Skip to content

Commit

Permalink
Fixed logging output for failed classifications (airbnb#965)
Browse files Browse the repository at this point in the history
* Fixed logging output for failed classifications

* Fixed typo in logging and switched from warn to debug
  • Loading branch information
blakemotl authored and ryandeivert committed Aug 12, 2019
1 parent e1fdb6b commit 82d4e83
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
21 changes: 17 additions & 4 deletions stream_alert/classifier/payload/payload_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,19 @@ def __len__(self):
)

def __repr__(self):
try:
record_data = json.dumps(self._record_data)
invalid_records = json.dumps(self.invalid_records)
except (TypeError, ValueError):
record_data = self._record_data
invalid_records = self.invalid_records
LOGGER.debug('A PayloadRecord has data that is not serializable as JSON')

if not self:
return '<{} valid:{}; raw record:{};>'.format(
self.__class__.__name__,
bool(self),
self._record_data
record_data
)

if self.invalid_records:
Expand All @@ -79,8 +87,8 @@ def __repr__(self):
self.log_schema_type,
len(self.parsed_records),
len(self.invalid_records),
self.invalid_records,
self._record_data
invalid_records,
record_data
)

return '<{} valid:{}; log type:{}; parsed records:{};>'.format(
Expand Down Expand Up @@ -213,12 +221,17 @@ def __repr__(self):
bool(self),
self.resource
)
try:
raw_record = json.dumps(self.raw_record)
except (TypeError, ValueError):
raw_record = self.raw_record
LOGGER.debug('A StreamPayload has data that is not serializable as JSON')

return '<{} valid:{}; resource:{}; raw record:{};>'.format(
self.__class__.__name__,
bool(self),
self.resource,
self.raw_record
raw_record
)

@classmethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def test_repr_invalid(self):
"""StreamPayload - Repr, Invalid"""
self._payload.fully_classified = False
expected_result = (
'<StreamPayload valid:False; resource:foobar; raw record:{\'key\': \'value\'};>'
'<StreamPayload valid:False; resource:foobar; raw record:{"key": "value"};>'
)
assert_equal(repr(self._payload), expected_result)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def test_repr(self):

def test_repr_invalid(self):
"""PayloadRecord - Repr, Invalid"""
expected_result = '<PayloadRecord valid:False; raw record:{\'key\': \'value\'};>'
expected_result = '<PayloadRecord valid:False; raw record:{"key": "value"};>'
assert_equal(repr(self._payload_record), expected_result)

def test_repr_invalid_records(self):
Expand All @@ -77,7 +77,7 @@ def test_repr_invalid_records(self):
)
expected_result = (
'<PayloadRecord valid:True; log type:foo:bar; parsed records:1; invalid records:1 '
'([{\'key\': \'value\'}]); raw record:{\'key\': \'value\'};>'
'([{"key": "value"}]); raw record:{"key": "value"};>'
)
assert_equal(repr(self._payload_record), expected_result)

Expand Down

0 comments on commit 82d4e83

Please sign in to comment.