How to use the pygelf.gelf.split function in pygelf

To help you get started, we’ve selected a few pygelf examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github keeprocking / pygelf / tests / test_core_functions.py View on Github external
def test_split():
    message = b'12345'
    header = b'\x1e\x0f'
    chunks = list(gelf.split(message, 2))
    expected = [
        (struct.pack('b', 0), struct.pack('b', 3), b'12'),
        (struct.pack('b', 1), struct.pack('b', 3), b'34'),
        (struct.pack('b', 2), struct.pack('b', 3), b'5')
    ]

    assert len(chunks) == len(expected)

    for index, chunk in enumerate(chunks):
        expected_index, expected_chunks_count, expected_chunk = expected[index]
        assert chunk[:2] == header
        assert chunk[10:11] == expected_index
        assert chunk[11:12] == expected_chunks_count
        assert chunk[12:] == expected_chunk
github keeprocking / pygelf / pygelf / handlers.py View on Github external
def send(self, s):
        if len(s) <= self.chunk_size:
            DatagramHandler.send(self, s)
            return

        chunks = gelf.split(s, self.chunk_size)
        for chunk in chunks:
            DatagramHandler.send(self, chunk)