def __init__(self, log_group_name, event_dict): """ Creates instance of the class Parameters ---------- event_dict : dict Dict of log event data returned by CloudWatch Logs API. https://docs.aws.amazon.com/AmazonCloudWatchLogs/latest/APIReference/API_FilteredLogEvent.html """ self.log_group_name = log_group_name if not event_dict: # If event is empty, just use default values for properties. We don't raise an error here because # this class is a data wrapper to the `events_dict`. It doesn't try to be smart. return self.log_stream_name = event_dict.get('logStreamName') self.message = event_dict.get('message', '') self.timestamp_millis = event_dict.get('timestamp') # Convert the timestamp from epoch to readable ISO timestamp, easier for formatting. if self.timestamp_millis: self.timestamp = timestamp_to_iso(int(self.timestamp_millis))
def test_must_work_on_timestamp_with_milliseconds(self): timestamp = 1530882594123 expected = "2018-07-06T13:09:54.123000" self.assertEqual(expected, timestamp_to_iso(timestamp))
def test_must_ignore_float_microseconds(self): timestamp = 1530882594123.9876 expected = "2018-07-06T13:09:54.123000" self.assertEquals(expected, timestamp_to_iso(timestamp))
def test_must_ignore_float_microseconds(self): timestamp = 1530882594123.9876 expected = "2018-07-06T13:09:54.123000" self.assertEqual(expected, timestamp_to_iso(timestamp))
def test_must_work_on_timestamp_with_milliseconds(self): timestamp = 1530882594123 expected = "2018-07-06T13:09:54.123000" self.assertEquals(expected, timestamp_to_iso(timestamp))