Beispiel #1
0
def test_autodiscover_repeat():
    config = {
        "handlers": ["logtron.handlers.ConsoleHandler"],
    }
    logger = autodiscover(
        refresh=True, config=config, discover_context=lambda: discover_context(sts_client=MockSTSClient(), refresh=True)
    )
    logger.info("test_autodiscover_repeat1")
    logger = autodiscover()
    logger.info("test_autodiscover_repeat2")
Beispiel #2
0
def test_cloudwatch_emf_non_flatten():
    config = {
        "handlers": ["logtron_aws.CloudWatchHandler"],
        "CloudWatchHandler": {
            "logs_client": MockLogsClient(),
            "interval_sec": 30,
            "emf_dimensions": [["kind", "smop"], ["kind"], "value"],
            "emf_metrics": [
                {
                    "Name": "value",
                    "Unit": "Count",
                },
                {
                    "Name": "fake",
                    "Unit": "Milliseconds",
                },
            ],
        },
    }
    logger = autodiscover(
        refresh=True,
        flatten=False,
        config=config,
        discover_context=lambda: discover_context(sts_client=MockSTSClient(), refresh=True),
    )
    logger.info("test_cloudwatch_emf_non_flatten", extra={"kind": "test", "value": 123})

    flush()
Beispiel #3
0
def test_empty_config():
    logger = autodiscover(
        refresh=True,
        logs_client=MockLogsClient(),
        discover_context=lambda: discover_context(sts_client=MockSTSClient(), refresh=True),
    )
    logger.info("test_empty_config")
    flush()
Beispiel #4
0
def test_cloudwatch_sts_client():
    config = {
        "handlers": ["logtron_aws.CloudWatchHandler"],
        "CloudWatchHandler": {
            "logs_client": MockLogsClient(),
            "interval_sec": 30,
        },
    }
    logger = autodiscover(refresh=True, config=config, sts_client=MockSTSClient())
    logger.info("test_cloudwatch_sts_client", extra={"test123": 123})

    flush()
Beispiel #5
0
def test_cloudwatch_default_handler():
    config = {
        "CloudWatchHandler": {
            "logs_client": MockLogsClient(),
            "interval_sec": 30,
        },
    }
    logger = autodiscover(
        refresh=True, config=config, discover_context=lambda: discover_context(sts_client=MockSTSClient(), refresh=True)
    )
    logger.info("test_cloudwatch_default_handler", extra={"test123": 123})

    flush()
Beispiel #6
0
def test_cloudwatch_existing_log_group():
    config = {
        "handlers": ["logtron_aws.CloudWatchHandler"],
        "CloudWatchHandler": {
            "logs_client": MockLogsClient(MockLogsPaginator([{"logGroups": ["foo"]}])),
            "interval_sec": 30,
        },
    }
    logger = autodiscover(
        refresh=True, config=config, discover_context=lambda: discover_context(sts_client=MockSTSClient(), refresh=True)
    )
    logger.info("test_cloudwatch_existing_log_group", extra={"test123": 123})

    flush()
Beispiel #7
0
def test_cloudwatch_close():
    config = {
        "handlers": ["logtron_aws.CloudWatchHandler"],
        "CloudWatchHandler": {
            "logs_client": MockLogsClient(),
            "interval_sec": 30,
        },
    }
    logger = autodiscover(
        refresh=True, config=config, discover_context=lambda: discover_context(sts_client=MockSTSClient(), refresh=True)
    )
    logger.info("test_cloudwatch_close", extra={"test123": 123})

    for i in logging.getLogger().handlers:
        i.close()
Beispiel #8
0
def test_cloudwatch_no_threading():
    config = {
        "handlers": ["logtron_aws.CloudWatchHandler"],
        "CloudWatchHandler": {
            "interval_sec": 30,
        },
    }
    logger = autodiscover(
        refresh=True,
        use_threading=False,
        logs_client=MockLogsClient(),
        config=config,
        discover_context=lambda: discover_context(sts_client=MockSTSClient(), refresh=True),
    )
    logger.info("test_cloudwatch_no_threading", extra={"test123": 123})

    flush()
Beispiel #9
0
def test_integration():
    config = {
        "handlers": ["logtron_aws.CloudWatchHandler"],
        "CloudWatchHandler": {
            "interval_sec":
            30,
            "emf_dimensions": [["kind", "smop"], ["kind"], "value"],
            "emf_metrics": [
                {
                    "Name": "value",
                    "Unit": "Count",
                },
                {
                    "Name": "fake",
                    "Unit": "Milliseconds",
                },
            ],
        },
    }
    logger = autodiscover(refresh=True, config=config)
    logger.info("test_integration", extra={"kind": "test", "value": 123})

    flush()