Registry / observability / pygelf

pygelf

JSON →
library0.4.3pypypi✓ verified 85d ago

pygelf provides logging handlers for the GELF (Graylog Extended Log Format) specification, allowing Python applications to send logs to Graylog servers or other GELF-compatible log management systems. It supports UDP, TCP, and HTTP transport protocols, including features like compression and chunking for large messages. The current version is 0.4.3, and it receives active maintenance with a moderate release cadence.

pip install pygelf
INSTALL
IMPORT
SIG · PYGELF
P
pygelf
observabilitypythonv0.4.3
Install
1.5s avg
Import
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.4.3 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 17.8MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 1.5s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

GelfUdpHandler
from pygelf import GelfUdpHandler
from pygelf import GELFUDPHandler

This quickstart demonstrates how to configure a Python logger with `GELFUDPHandler` to send log messages to a Graylog instance. It shows basic info, warning, and exception logging, including how to pass extra fields to GELF. Remember to replace placeholder host/port or set them via environment variables to match your Graylog setup.

import logging import os from pygelf import GELFUDPHandler # Replace with your Graylog host and port, or set as environment variables GRAYLOG_HOST = os.environ.get('GRAYLOG_HOST', '127.0.0.1') GRAYLOG_PORT = int(os.environ.get('GRAYLOG_PORT', '12201')) # Default GELF UDP port logger = logging.getLogger('my_app') logger.setLevel(logging.INFO) # Configure GELF UDP handler handler = GELFUDPHandler( host=GRAYLOG_HOST, port=GRAYLOG_PORT, _source_host='my_python_app', # Custom field example include_extra_fields=True # Include extra dict fields in log record ) logger.addHandler(handler) # Example log messages logger.info("This is an informational message.") logger.warning("A warning occurred!", extra={'user_id': 123, 'transaction_id': 'abc-xyz'}) try: 1 / 0 except ZeroDivisionError: logger.exception("An error occurred during division.") print(f"Logs sent to {GRAYLOG_HOST}:{GRAYLOG_PORT}. Check your Graylog instance.")
Debug
Known issues
gotchaEnsure you are using the correct GELF handler (UDP, TCP, or HTTP) and that the `host` and `port` parameters match your Graylog input configuration.
fix
Verify your Graylog input type and its listening address/port. For UDP, the default port is 12201; for TCP, it's 12202; for HTTP, it's typically 12201 (HTTP GELF input) on a dedicated Graylog HTTP input.
affects: All versions
gotchaVery large log messages (e.g., stack traces, large JSON payloads) might exceed UDP packet limits or be rejected by Graylog if not properly compressed or chunked.
fix
Set `compress=True` (defaults to `zlib`) on your handler. pygelf handles chunking automatically for UDP, but compression helps reduce the number of chunks and total payload size, improving reliability for large messages.
affects: All versions
gotchaCustom `extra` fields passed to `logger.info(..., extra={'key': 'value'})` are not included in the GELF message by default.
fix
Add `include_extra_fields=True` to your GELF handler initialization, e.g., `GELFUDPHandler(host=..., include_extra_fields=True)` to ensure these fields are sent.
affects: All versions
Upgrade
Version history
0.4.3latest on PyPI · released Jun 14, 2025
Audit
Dependencies

No dependency data recorded yet.

Agent activity
33 hits · last 30 days
node
30
OpenAI (training)
2
Amazon
1
Resources
pygelf — pip install pygelf · libregistry