{"id":4734,"library":"python3-logstash","title":"Python3 Logstash Logging Handler","description":"The `python3-logstash` library, version `0.4.80`, provides Python logging handlers for sending messages to a Logstash server over UDP or TCP. Originally created as a Python 3 fork of the `python-logstash` library, this specific package was last updated in July 2018. Due to its lack of recent updates, it appears to be unmaintained. For actively maintained alternatives with asynchronous capabilities, users often consider `python-logstash-async`.","status":"abandoned","version":"0.4.80","language":"en","source_language":"en","source_url":"https://github.com/israel-fl/python3-logstash","tags":["logging","logstash","elk","handler","python3"],"install":[{"cmd":"pip install python3-logstash","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Required for using the AMQPLogstashHandler to send logs via AMQP.","package":"pika","optional":true}],"imports":[{"symbol":"LogstashHandler","correct":"from logstash import LogstashHandler"},{"symbol":"TCPLogstashHandler","correct":"from logstash import TCPLogstashHandler"},{"note":"Requires 'pika' package to be installed.","symbol":"AMQPLogstashHandler","correct":"from logstash import AMQPLogstashHandler"}],"quickstart":{"code":"import logging\nimport logstash\nimport sys\nimport os\n\nhost = os.environ.get('LOGSTASH_HOST', 'localhost')\nport = int(os.environ.get('LOGSTASH_PORT', '5959'))\n\ntest_logger = logging.getLogger('python-logstash-logger')\ntest_logger.setLevel(logging.INFO)\n\n# Example for UDP handler\ntest_logger.addHandler(logstash.LogstashHandler(host, port, version=1))\n\n# Example for TCP handler (uncomment to use)\n# test_logger.addHandler(logstash.TCPLogstashHandler(host, port, version=1))\n\ntest_logger.error('python-logstash: test logstash error message.')\ntest_logger.info('python-logstash: test logstash info message.')\ntest_logger.warning('python-logstash: test logstash warning message.')\n\n# Add extra fields to logstash message\nextra = {\n    'test_string': 'python version: ' + repr(sys.version_info),\n    'test_boolean': True,\n    'test_dict': {'a': 1, 'b': 'c'},\n    'test_float': 1.23,\n    'test_integer': 123,\n    'test_list': [1, 2, '3'],\n}\ntest_logger.info('python-logstash: test extra fields', extra=extra)\n\ntry:\n    1 / 0\nexcept ZeroDivisionError:\n    test_logger.exception('python-logstash-logger: Exception with stack trace!')","lang":"python","description":"This quickstart demonstrates how to configure a logger with `LogstashHandler` (UDP) or `TCPLogstashHandler` to send messages to a Logstash instance. It includes examples for different log levels and adding custom `extra` fields. Ensure environment variables `LOGSTASH_HOST` and `LOGSTASH_PORT` are set, or it will default to `localhost:5959`."},"warnings":[{"fix":"Review the Python logging `Formatter` documentation to understand reserved keys and choose unique names for custom fields.","message":"Avoid using reserved logging system keys (e.g., `message`, `asctime`, `levelname`) in the `extra` dictionary passed to log methods. This can cause conflicts or unexpected behavior, as these keys are used internally by the Python logging system.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Consider migrating to `python-logstash` or, for asynchronous logging and more features, `python-logstash-async`.","message":"The `python3-logstash` library is a fork that has not been updated since July 2018 (v0.4.80). The original `python-logstash` (v0.4.8) received updates in March 2022. This means `python3-logstash` likely lacks bug fixes and features present in its upstream or in more actively maintained alternatives like `python-logstash-async`.","severity":"breaking","affected_versions":"All versions (due to lack of future maintenance)"},{"fix":"For non-blocking, asynchronous log sending, consider using `python-logstash-async`, which is designed for this purpose.","message":"This library uses synchronous network calls for sending logs, which can block the main application thread if Logstash is unavailable or experiences high latency. For applications where logging performance is critical (e.g., web servers), this can introduce significant overhead.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always explicitly set `version=1` in your handler configuration unless you have a specific need for an older schema.","message":"The `version` parameter in `LogstashHandler` and `TCPLogstashHandler` refers to the Logstash event schema version. While the default is `0` for backward compatibility, `version=1` is recommended for Logstash 1.2.x and later for a modern JSON schema.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}