{"id":5951,"library":"graypy","title":"graypy","description":"graypy is a Python library that provides logging handlers for sending messages in the Graylog Extended Log Format (GELF). It integrates with Python's standard `logging` module and supports various transport protocols including UDP, TCP, TLS, HTTP, and RabbitMQ. The current version is 2.1.0, and while there isn't a strict release cadence, major versions have introduced breaking changes.","status":"active","version":"2.1.0","language":"en","source_language":"en","source_url":"https://github.com/severb/graypy","tags":["logging","graylog","gelf","log management","handler"],"install":[{"cmd":"pip install graypy","lang":"bash","label":"Install basic graypy package"}],"dependencies":[],"imports":[{"symbol":"GELFUDPHandler","correct":"from graypy import GELFUDPHandler"},{"symbol":"GELFTCPHandler","correct":"from graypy import GELFTCPHandler"},{"symbol":"GELFTLSHandler","correct":"from graypy import GELFTLSHandler"},{"symbol":"GELFHTTPHandler","correct":"from graypy import GELFHTTPHandler"},{"symbol":"GELFRabbitHandler","correct":"from graypy import GELFRabbitHandler"},{"note":"`GELFHandler` was deprecated and removed in graypy 1.x.x; use `GELFUDPHandler` instead.","wrong":"from graypy import GELFHandler","symbol":"GELFHandler","correct":"from graypy import GELFUDPHandler"},{"note":"`GELFTcpHandler` was deprecated and restructured into `GELFTCPHandler` and `GELFTLSHandler` in graypy 1.x.x.","wrong":"from graypy import GELFTcpHandler","symbol":"GELFTcpHandler","correct":"from graypy import GELFTCPHandler"}],"quickstart":{"code":"import logging\nimport graypy\nimport os\n\n# Configure Graylog host and port, using environment variables for security\nGRAYLOG_HOST = os.environ.get('GRAYLOG_HOST', 'localhost')\nGRAYLOG_PORT = int(os.environ.get('GRAYLOG_PORT', 12201))\n\n# Get a logger instance\nmy_logger = logging.getLogger('my_app_logger')\nmy_logger.setLevel(logging.DEBUG)\n\n# Create a GELF UDP handler\nhandler = graypy.GELFUDPHandler(GRAYLOG_HOST, GRAYLOG_PORT)\nmy_logger.addHandler(handler)\n\n# Send a log message\nmy_logger.debug('Hello Graylog from graypy!')\nmy_logger.info('This is an informational message.')\nmy_logger.warning('Something might be wrong here.')\n\ntry:\n    1 / 0\nexcept ZeroDivisionError:\n    my_logger.exception('An error occurred!')\n\nprint(f\"Log messages sent to Graylog at {GRAYLOG_HOST}:{GRAYLOG_PORT} (UDP).\")","lang":"python","description":"This quickstart demonstrates how to configure a basic UDP logging handler (`GELFUDPHandler`) to send messages to a Graylog server. It uses environment variables for the Graylog host and port, which is a common practice for configuration management. Ensure your Graylog server has a GELF UDP input configured on the specified port."},"warnings":[{"fix":"Replace `GELFHandler` with `GELFUDPHandler` and `GELFTcpHandler` with `GELFTCPHandler` or `GELFTLSHandler` based on your protocol requirements.","message":"The `GELFHandler` and `GELFTcpHandler` classes were removed in `graypy` version 1.x.x. Users migrating from 0.x.x to 1.x.x or newer must update their code to use `GELFUDPHandler`, `GELFTCPHandler`, or `GELFTLSHandler` respectively.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"For high-priority or critical logs, consider using `GELFTCPHandler`, `GELFTLSHandler`, or `GELFRabbitHandler` and configure a corresponding input on your Graylog server.","message":"`GELFUDPHandler` sends logs via UDP, which is a connectionless protocol and does not guarantee message delivery. Critical logs that must not be lost should be sent via `GELFTCPHandler`, `GELFTLSHandler`, `GELFHTTPHandler`, or `GELFRabbitHandler` for more reliable transport.","severity":"gotcha","affected_versions":"All"},{"fix":"Refer to `graypy` documentation and RabbitMQ configuration guides for proper setup of queues and exchanges for AMQP-based GELF logging.","message":"When using `GELFRabbitHandler`, you must manually configure RabbitMQ with a GELF-compatible queue and bind it to a logging exchange. Graylog then consumes messages from this AMQP queue.","severity":"gotcha","affected_versions":"All"},{"fix":"Monitor the GitHub repository issues and commits for updates, or pin `graypy` to a specific version to avoid unexpected changes.","message":"There is no formal changelog maintained for `graypy` on GitHub, which can make it challenging to track specific changes, new features, or breaking alterations between versions.","severity":"gotcha","affected_versions":"All"},{"fix":"Verify container networking configurations, ensuring proper hostname resolution or direct IP addressing between your application and Graylog instances.","message":"When deploying `graypy` in containerized environments (e.g., with Docker or Kubernetes, especially with Django applications), ensure that the application container and the Graylog container are on the same network and configured with correct hostnames or IP addresses for communication.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-14T00:00:00.000Z","next_check":"2026-07-13T00:00:00.000Z"}