Skip to main content

Async UDP client for sending GELF messages to Graylog

Project description

Async GELF Client

Fully async UDP client for sending GELF messages to Graylog. Uses native asyncio for maximum performance, automatically compresses messages larger than 8KB, and runs all blocking operations in thread pool to avoid blocking the event loop.

Installation

pip install async-gelf-client

Usage

import asyncio
from asyncgelf import AsyncGelfClient, GelfMessage

async def main():
    client = AsyncGelfClient(host="localhost", port=12201)
    
    message = GelfMessage.create(
        short_message="Hello Graylog",
        level=6,
        host="myapp"
    )
    
    await client.send(message)

asyncio.run(main())

Parallel sending (high performance)

import asyncio
from asyncgelf import AsyncGelfClient, GelfMessage

async def main():
    client = AsyncGelfClient(host="localhost", port=12201)
    
    # Send multiple messages in parallel without blocking
    messages = [
        GelfMessage.create(short_message=f"Message {i}", level=6, host="myapp")
        for i in range(100)
    ]
    
    await asyncio.gather(*[client.send(msg) for msg in messages])

asyncio.run(main())

API

AsyncGelfClient

Fully async UDP client for sending GELF messages. All blocking operations (JSON serialization, gzip compression) run in thread pool.

Parameters:

  • host (str): Graylog server hostname or IP address
  • port (int): UDP port (default: 12201)
  • compress_threshold (int): Message size in bytes to trigger compression (default: 8192)

Methods:

  • async send(message: dict[str, Any]) -> None: Sends GELF message

GelfMessage

GELF message builder with static methods.

Methods:

GelfMessage.create(...)

Creates a properly formatted GELF message.

Parameters:

  • short_message (str): Short log description (required)
  • full_message (str | None): Full log description (optional)
  • level (int): Syslog level (7=debug, 6=info, 4=warning, 3=error, 2=critical)
  • host (str): Host/application name
  • timestamp (float | None): Unix timestamp (if None - current time)
  • **additional_fields: Additional fields (will be prefixed with _)

Returns: dict with GELF message

GelfMessage.convert_log_level(python_level)

Converts Python logging level to Syslog level for GELF.

Parameters:

  • python_level (int): Python logging level (logging.DEBUG, logging.INFO, etc.)

Returns: int - Syslog level

Requirements

  • Python >= 3.10

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

async_gelf_client-0.2.1.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

async_gelf_client-0.2.1-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file async_gelf_client-0.2.1.tar.gz.

File metadata

  • Download URL: async_gelf_client-0.2.1.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for async_gelf_client-0.2.1.tar.gz
Algorithm Hash digest
SHA256 33b7cd6e2a6fb621658fe55d3b6d01e4f0f51742fa797572c0a4bb4692b01c92
MD5 58db8af052f14df8cf6ec96187e0a8a3
BLAKE2b-256 6a6199ffa1d6b478a833cbb428f3b125ca3e33f581365b3a150ab3fddb8cc3cd

See more details on using hashes here.

File details

Details for the file async_gelf_client-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for async_gelf_client-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d33b7ac4fa2168d7a7648f1a3fbbcc5d7a8ba6ce34518a877c8d105411604ed0
MD5 f0d9cc97f558f491ce45485a8add0e5f
BLAKE2b-256 1d4538e8b88b28d5ff683badac51919bb84f057aa3441f2709bc4265238b7d39

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page