示例#1
0
    def test_logs_to_datadog(self, mock_dd):
        handler = DatadogLogHandler()

        record = logging.makeLogRecord({"msg": "Some message"})

        handler.emit(record)

        mock_dd.api.Event.create.assert_called_with(title="Some message",
                                                    text="Some message")
示例#2
0
    def test_includes_mentions_from_constructor(self, mock_dd):
        handler = DatadogLogHandler(mentions=["@mention-1", "@mention-2"])

        record = logging.makeLogRecord({"msg": "Some message"})

        handler.emit(record)

        mock_dd.api.Event.create.assert_called_with(
            title="Some message", text="Some message\n\n@mention-1 @mention-2")
示例#3
0
    def test_includes_tags_from_constructor(self, mock_dd):
        handler = DatadogLogHandler(tags=["some:tag"])

        record = logging.makeLogRecord({"msg": "Some message"})

        handler.emit(record)

        mock_dd.api.Event.create.assert_called_with(title="Some message",
                                                    text="Some message",
                                                    tags=["some:tag"])
    def test_includes_mentions_from_constructor(self, mock_dd):
        handler = DatadogLogHandler(mentions=["@mention-1", "@mention-2"])

        record = logging.makeLogRecord({
            "msg": "Some message"
        })

        handler.emit(record)

        mock_dd.api.Event.create.assert_called_with(
            title="Some message", text="Some message\n\n@mention-1 @mention-2")
    def test_logs_to_datadog(self, mock_dd):
        handler = DatadogLogHandler()

        record = logging.makeLogRecord({
            "msg": "Some message"
        })

        handler.emit(record)

        mock_dd.api.Event.create.assert_called_with(
            title="Some message", text="Some message")
    def test_includes_tags_from_constructor(self, mock_dd):
        handler = DatadogLogHandler(tags=["some:tag"])

        record = logging.makeLogRecord({
            "msg": "Some message"
        })

        handler.emit(record)

        mock_dd.api.Event.create.assert_called_with(
            title="Some message", text="Some message",
            tags=["some:tag"])
示例#7
0
    def test_includes_maps_debug_to_info(self, mock_dd):
        handler = DatadogLogHandler()

        record = logging.makeLogRecord({
            "msg": "Some message",
            "levelno": logging.DEBUG
        })

        handler.emit(record)

        mock_dd.api.Event.create.assert_called_with(title="Some message",
                                                    text="Some message",
                                                    alert_type="info")
示例#8
0
    def test_includes_maps_critical_to_error(self, mock_dd):
        handler = DatadogLogHandler()

        record = logging.makeLogRecord({
            "msg": "Some message",
            "levelno": logging.CRITICAL
        })

        handler.emit(record)

        mock_dd.api.Event.create.assert_called_with(title="Some message",
                                                    text="Some message",
                                                    alert_type="error")
    def test_includes_maps_debug_to_info(self, mock_dd):
        handler = DatadogLogHandler()

        record = logging.makeLogRecord({
            "msg": "Some message",
            "levelno": logging.DEBUG
        })

        handler.emit(record)

        mock_dd.api.Event.create.assert_called_with(
            title="Some message", text="Some message",
            alert_type="info")
    def test_includes_maps_critical_to_error(self, mock_dd):
        handler = DatadogLogHandler()

        record = logging.makeLogRecord({
            "msg": "Some message",
            "levelno": logging.CRITICAL
        })

        handler.emit(record)

        mock_dd.api.Event.create.assert_called_with(
            title="Some message", text="Some message",
            alert_type="error")
    def test_logs_formatted_message_as_text(self, mock_dd):
        handler = DatadogLogHandler()

        exc_info = make_exc_info()

        record = logging.makeLogRecord({
            "msg": "Some message",
            "exc_info": exc_info
        })

        expected_text = "\n".join(
            ["Some message", "".join(traceback.format_exception(*exc_info))]).rstrip("\n")

        handler.emit(record)

        mock_dd.api.Event.create.assert_called_with(
            title="Some message", text=expected_text)
示例#12
0
    def test_logs_formatted_message_as_text(self, mock_dd):
        handler = DatadogLogHandler()

        exc_info = make_exc_info()

        record = logging.makeLogRecord({
            "msg": "Some message",
            "exc_info": exc_info
        })

        expected_text = "\n".join(
            ["Some message",
             "".join(traceback.format_exception(*exc_info))]).rstrip("\n")

        handler.emit(record)

        mock_dd.api.Event.create.assert_called_with(title="Some message",
                                                    text=expected_text)