<commit_before>#!/usr/bin/python
# -*- coding: utf-8 -*-

""""""

import logging
import pytest
from graypy import GELFTLSHandler, GELFTCPHandler, GELFUDPHandler, \
    GELFHTTPHandler

from tests.helper import  TEST_CERT, TEST_TCP_PORT, TEST_HTTP_PORT, \
    TEST_TLS_PORT, TEST_UDP_PORT
from tests.integration.helper import get_unique_message, get_graylog_response


class DummyFilter(logging.Filter):
    def filter(self, record):
        record.ozzy = 'diary of a madman'
        record.van_halen = 1984
        record.id = 42
        return True


@pytest.fixture(params=[
    GELFTCPHandler('127.0.0.1', TEST_TCP_PORT, extra_fields=True),
    GELFUDPHandler('127.0.0.1', TEST_UDP_PORT, extra_fields=True),
    GELFUDPHandler('127.0.0.1', TEST_UDP_PORT, compress=False, extra_fields=True),
    GELFHTTPHandler('127.0.0.1', TEST_HTTP_PORT, extra_fields=True),
    GELFHTTPHandler('127.0.0.1', TEST_HTTP_PORT, compress=False, extra_fields=True),
    GELFTLSHandler('127.0.0.1', TEST_TLS_PORT, extra_fields=True),
    GELFTLSHandler('127.0.0.1', TEST_TLS_PORT, validate=True, ca_certs=TEST_CERT, extra_fields=True),
])
def handler(request):
    return request.param


@pytest.yield_fixture
def logger(handler):
    logger = logging.getLogger('test')
    dummy_filter = DummyFilter()
    logger.addFilter(dummy_filter)
    logger.addHandler(handler)
    yield logger
    logger.removeHandler(handler)
    logger.removeFilter(dummy_filter)


def test_dynamic_fields(logger):
    message = get_unique_message()
    logger.error(message)<commit_msg>adding annotation for skipping if no local graylog is up<commit_after>#!/usr/bin/python
# -*- coding: utf-8 -*-

""""""

import logging
import pytest
from graypy import GELFTLSHandler, GELFTCPHandler, GELFUDPHandler, \
    GELFHTTPHandler

from tests.helper import  TEST_CERT, TEST_TCP_PORT, TEST_HTTP_PORT, \
    TEST_TLS_PORT, TEST_UDP_PORT
from tests.integration import LOCAL_GRAYLOG_UP
from tests.integration.helper import get_unique_message, get_graylog_response


class DummyFilter(logging.Filter):
    def filter(self, record):
        record.ozzy = 'diary of a madman'
        record.van_halen = 1984
        record.id = 42
        return True


@pytest.fixture(params=[
    GELFTCPHandler('127.0.0.1', TEST_TCP_PORT, extra_fields=True),
    GELFUDPHandler('127.0.0.1', TEST_UDP_PORT, extra_fields=True),
    GELFUDPHandler('127.0.0.1', TEST_UDP_PORT, compress=False, extra_fields=True),
    GELFHTTPHandler('127.0.0.1', TEST_HTTP_PORT, extra_fields=True),
    GELFHTTPHandler('127.0.0.1', TEST_HTTP_PORT, compress=False, extra_fields=True),
    GELFTLSHandler('127.0.0.1', TEST_TLS_PORT, extra_fields=True),
    GELFTLSHandler('127.0.0.1', TEST_TLS_PORT, validate=True, ca_certs=TEST_CERT, extra_fields=True),
])
def handler(request):
    return request.param


@pytest.yield_fixture
def logger(handler):
    logger = logging.getLogger('test')
    dummy_filter = DummyFilter()
    logger.addFilter(dummy_filter)
    logger.addHandler(handler)
    yield logger
    logger.removeHandler(handler)
    logger.removeFilter(dummy_filter)


@pytest.mark.skipif(not LOCAL_GRAYLOG_UP,
                    reason="local graylog instance not up")
def test_dynamic_fields(logger):
    message = get_unique_message()
    logger.error(message)
{'fraction_non_alphanumeric': 0.11449451887941535, 'fraction_numerical': 0.02984165651644336, 'mean_word_length': 4.548986486486487, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 14, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4877604', 'n_tokens_mistral': 1198, 'n_tokens_neox': 1157, 'n_words': 201}