def test_must_ignore_if_keyword_is_absent(self): colored = Mock() input_msg = "this keyword some keyword other keyword" event = LogEvent("group_name", {"message": input_msg}) result = KeywordHighlighter().highlight_keywords(event, colored) self.assertEqual(result.message, input_msg) colored.underline.assert_not_called()
def test_must_highlight_all_keywords(self): input_msg = "this keyword some keyword other keyword" keyword = "keyword" color_result = "colored" expected_msg = "this colored some colored other colored" colored = Mock() colored.underline.return_value = color_result event = LogEvent("group_name", {"message": input_msg}) result = KeywordHighlighter(keyword).highlight_keywords(event, colored) self.assertEqual(result.message, expected_msg) colored.underline.assert_called_with(keyword)
def formatter(self): """ Creates and returns a Formatter capable of nicely formatting Lambda function logs Returns ------- LogsFormatter """ formatter_chain = [ LambdaLogMsgFormatters.colorize_errors, # Format JSON "before" highlighting the keywords. Otherwise, JSON will be invalid from all the # ANSI color codes and fail to pretty print JSONMsgFormatter.format_json, KeywordHighlighter(self._filter_pattern).highlight_keywords, ] return LogsFormatter(self.colored, formatter_chain)