Ejemplo n.º 1
0
 def test_datadog_json_formatter(self, capfd):
     fmt = get_formatter("json")
     handler = ColorizingStreamHandler()
     handler.setFormatter(fmt)
     if logger.handlers:
         logger.removeHandler(logger.handlers[0])
     logger.addHandler(handler)
     logger.info("json message")
     captured = capfd.readouterr()
     message_keys = json.loads(captured.err).keys()
     expected_keys = [
         "timestamp",
         "logger.name",
         "logger.method_name",
         "service_name",
         "service_version",
         "message",
         "funcName",
         "levelname",
         "levelno",
         "pathname",
         "filename",
         "module",
     ]
     for key in expected_keys:
         assert key in message_keys
Ejemplo n.º 2
0
    def test_datadog_json_formatter(self, logger, caplog):
        fmt = get_formatter("json")
        handler = ColorizingStreamHandler()
        handler.setFormatter(fmt)
        if logger.handlers:
            logger.removeHandler(logger.handlers[0])
        logger.addHandler(handler)

        logger.info("json message")
Ejemplo n.º 3
0
    def test_datadog_json_formatter_with_exc_info(self, capfd):
        fmt = get_formatter("json")
        handler = ColorizingStreamHandler()
        handler.setFormatter(fmt)
        if logger.handlers:
            logger.removeHandler(logger.handlers[0])
        logger.addHandler(handler)

        logger.info("json message", exc_info=Exception(":("))
        captured = capfd.readouterr()
        message_keys = json.loads(captured.err).keys()

        expected_keys = [
            "error.kind",
            "error.message",
            "error.stack",
        ]
        for key in expected_keys:
            assert key in message_keys