{"id":21541,"library":"logstash-formatter","title":"logstash-formatter","description":"A JSON log formatter for logstash, typically used with Python's logging module. Current version 0.5.17. Infrequently updated; last release in 2019.","status":"maintenance","version":"0.5.17","language":"python","source_language":"en","source_url":"https://github.com/exoscale/python-logstash-formatter","tags":["logging","logstash","json","formatter"],"install":[{"cmd":"pip install logstash-formatter","lang":"bash","label":"Install via pip"}],"dependencies":[],"imports":[{"note":"Old import path from earlier versions; now use top-level module.","wrong":"from logstash_formatter.formatter import LogstashFormatter","symbol":"LogstashFormatter","correct":"from logstash_formatter import LogstashFormatter"}],"quickstart":{"code":"import logging\nfrom logstash_formatter import LogstashFormatter\n\nhandler = logging.StreamHandler()\nformatter = LogstashFormatter()\nhandler.setFormatter(formatter)\nlogger = logging.getLogger('my_logger')\nlogger.addHandler(handler)\nlogger.setLevel(logging.INFO)\nlogger.info('Hello, logstash!', extra={'custom_field': 'value'})","lang":"python","description":"Basic setup with a stream handler. The extra dict becomes JSON fields."},"warnings":[{"fix":"Use the extra parameter to add structured data instead of formatting it into the message string.","message":"Message string is automatically included; do not embed JSON in the message itself as it may interfere with parsing.","severity":"gotcha","affected_versions":"all"},{"fix":"Set the 'format' parameter to 'UNIX' or custom format, or ensure your logger's timezone is consistent.","message":"Timestamp defaults to the current time in UTC in ISO8601 format; timezone awareness may cause issues if your logs are not in UTC.","severity":"gotcha","affected_versions":"all"},{"fix":"Upgrade to Python 3. Use version 0.5.17 on Python 3.6+.","message":"Python 2 support is effectively abandoned; the library may not install or function correctly on Python 2.","severity":"deprecated","affected_versions":"0.5.x"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Run 'pip install logstash-formatter' and use 'from logstash_formatter import LogstashFormatter'.","cause":"Package not installed or import path incorrect.","error":"ModuleNotFoundError: No module named 'logstash_formatter'"},{"fix":"Check the constructor: LogstashFormatter(fmt=None, datefmt=None, extra=None). Remove unsupported arguments.","cause":"Passing parameters that don't match the constructor signature (e.g., 'version' instead of 'fmt' or 'datefmt').","error":"TypeError: __init__() got an unexpected keyword argument 'version'"},{"fix":"Pin to logstash-formatter==0.5.17 and ensure Python >=3.6. If issues persist, consider switching to python-json-logger.","cause":"Incompatibility with Python logging internals in newer Python versions (3.8+).","error":"AttributeError: 'LogstashFormatter' object has no attribute '_style'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}