def test_status_field_issue(logger): message = get_unique_message() logger.error(message, extra={"status": "OK"}) graylog_response = get_graylog_response(message, fields=["status"]) assert message == graylog_response["message"] assert "long_message" not in graylog_response assert "timestamp" in graylog_response assert "OK" == graylog_response["status"]
def test_non_status_field_log(logger): message = get_unique_message() logger.error(message, extra={"foo": "bar"}) graylog_response = get_graylog_response(message, fields=["foo"]) assert message == graylog_response["message"] assert "long_message" not in graylog_response assert "timestamp" in graylog_response assert "bar" == graylog_response["foo"]
def test_common_logging(logger): """Test sending a common usage log""" message = get_unique_message() logger.error(message) graylog_response = get_graylog_response(message) assert message == graylog_response["message"] assert "long_message" not in graylog_response assert "timestamp" in graylog_response assert SYSLOG_LEVELS[logging.ERROR] == graylog_response["level"]
def test_dynamic_fields(logger): message = get_unique_message() logger.error(message) graylog_response = get_graylog_response(message, fields=['ozzy', 'van_halen']) assert message == graylog_response['message'] assert "long_message" not in graylog_response assert "timestamp" in graylog_response assert 'diary of a madman' == graylog_response['ozzy'] assert 1984 == graylog_response['van_halen'] assert 42 != graylog_response['_id'] assert 'id' not in graylog_response
def test_chunked_logging(): """Test sending a log that requires chunking to be fully sent""" logger = logging.getLogger("test_chunked_logger") handler = GELFUDPHandler("127.0.0.1", TEST_UDP_PORT, chunk_size=10) logger.addHandler(handler) message = get_unique_message() logger.error(message) graylog_response = get_graylog_response(message) assert message == graylog_response["message"] assert "long_message" not in graylog_response assert "timestamp" in graylog_response assert SYSLOG_LEVELS[logging.ERROR] == graylog_response["level"]
def test_dynamic_fields(logger): message = get_unique_message() logger.error(message) graylog_response = get_graylog_response(message, fields=["ozzy", "van_halen"]) assert message == graylog_response["message"] assert "long_message" not in graylog_response assert "timestamp" in graylog_response assert "diary of a madman" == graylog_response["ozzy"] assert 1984 == graylog_response["van_halen"] assert 42 != graylog_response["_id"] assert "id" not in graylog_response
def test_chunked_logging(): """Test sending a common usage log that requires chunking to be fully sent""" logger = logging.getLogger("test_chunked_logger") handler = GELFUDPHandler("127.0.0.1", TEST_UDP_PORT, chunk_size=10) logger.addHandler(handler) message = get_unique_message() logger.error(message) graylog_response = get_graylog_response(message) assert message == graylog_response["message"] assert "long_message" not in graylog_response assert "timestamp" in graylog_response assert SYSLOG_LEVELS[logging.ERROR] == graylog_response["level"]
def test_debug_mode(logger): message = get_unique_message() logger.error(message) graylog_response = get_graylog_response(message, fields=["function", "pid", "thread_name"]) assert message == graylog_response['message'] assert "long_message" not in graylog_response assert "timestamp" in graylog_response assert graylog_response['file'].endswith("test_debugging_fields.py") assert 'test_debug_mode' == graylog_response['function'] assert 'line' in graylog_response assert "file" in graylog_response assert "pid" in graylog_response assert "thread_name" in graylog_response
def test_debug_mode(logger): message = get_unique_message() logger.error(message) graylog_response = get_graylog_response( message, fields=["function", "pid", "thread_name"]) assert message == graylog_response['message'] assert "long_message" not in graylog_response assert "timestamp" in graylog_response assert graylog_response['file'].endswith("test_debugging_fields.py") assert 'test_debug_mode' == graylog_response['function'] assert 'line' in graylog_response assert "file" in graylog_response assert "pid" in graylog_response assert "thread_name" in graylog_response