{"id":28546387,"url":"https://github.com/ulule/python-logstash-formatter","last_synced_at":"2025-10-08T23:35:25.188Z","repository":{"id":62576780,"uuid":"9800122","full_name":"ulule/python-logstash-formatter","owner":"ulule","description":"python JSON log formatter with a logstash compatible schema","archived":false,"fork":false,"pushed_at":"2019-08-12T16:08:29.000Z","size":43,"stargazers_count":158,"open_issues_count":3,"forks_count":61,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-09-29T01:29:31.018Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ulule.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-05-01T21:08:53.000Z","updated_at":"2024-03-22T09:30:29.000Z","dependencies_parsed_at":"2022-11-03T19:55:14.608Z","dependency_job_id":null,"html_url":"https://github.com/ulule/python-logstash-formatter","commit_stats":null,"previous_names":["exoscale/python-logstash-formatter"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/ulule/python-logstash-formatter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ulule%2Fpython-logstash-formatter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ulule%2Fpython-logstash-formatter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ulule%2Fpython-logstash-formatter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ulule%2Fpython-logstash-formatter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ulule","download_url":"https://codeload.github.com/ulule/python-logstash-formatter/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ulule%2Fpython-logstash-formatter/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279000733,"owners_count":26082862,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-08T02:00:06.501Z","response_time":56,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-06-09T23:39:16.689Z","updated_at":"2025-10-08T23:35:25.173Z","avatar_url":"https://github.com/ulule.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# logstash_formatter: JSON logs for logstash\nThis library is provided to allow standard python logging to output log data\nas json objects ready to be shipped out to logstash.\n\nThis project has been originally open sourced by [exoscale](https://www.exoscale.ch/) (which is a great hosting service btw),\nthanks to them.\n\n## Installing\nUsing `pip` ([PyPI](https://pypi.python.org/pypi/logstash_formatter)):\n~~~\npip install logstash_formatter\n~~~\n\nManual:\n~~~\ngit clone https://github.com/ulule/python-logstash-formatter.git\ncd python-logstash-formatter\npython setup.py install\n~~~\n\n## Usage\nJson outputs are provided by the LogstashFormatter logging formatter.\n~~~python\nimport logging, sys\nfrom logstash_formatter import LogstashFormatterV1\n\n# configure logging\nhandler = logging.StreamHandler(stream=sys.stdout)\nhandler.setFormatter(LogstashFormatterV1())\nlogging.basicConfig(handlers=[handler], level=logging.INFO)\n\n# use it\nlogging.info(\"my log\")\n~~~\n\nThe LogstashFormatter may take the following named parameters:\n* `fmt`: Config as a JSON string that supports:\n  * `extra`: provide extra fields always present in logs.\n  * `source_host`: override source host name.\n* `json_cls`: JSON encoder to forward to `json.dump`.\n* `json_default`: Default JSON representation for unknown types,\n  by default coerce everything to a string.\n\n`LogstashFormatterV1` adheres to the more 1.2.0 schema and will not update\nfields, apart from a special handling of `msg` which will be updated to\n`message` when applicable.\n\nYou can also add extra fields to your json output by specifying a dict in place of message, or by specifying\nthe named argument `extra` as a dictionary. When supplying the `exc_info` named argument with a truthy value,\nand if an exception is found on the stack, its traceback will be attached to the payload as well.\n\n~~~python\nlogger.info({\"account\": 123, \"ip\": \"172.20.19.18\"})\nlogger.info(\"classic message for account: {account}\", extra={\"account\": account})\n\ntry:\n    h = {}\n    h['key']\nexcept:\n    logger.info(\"something unexpected happened\", exc_info=True)\n~~~\n\n## Sample output for LogstashFormatter\nThe following keys will be found in the output JSON:\n* `@source_host`: source hostname for the log\n* `@timestamp`: ISO 8601 timestamp\n* `@message`: short message for this log\n* `@fields`: all extra fields\n\n~~~json\n{\n    \"@fields\": {\n        \"account\": \"pyr\",\n        \"args\": [],\n        \"created\": 1367480388.013037,\n        \"exception\": [\n            \"Traceback (most recent call last):\\n\",\n            \"  File \\\"test.py\\\", line 16, in \u003cmodule\u003e\\n    k['unknown']\\n\",\n            \"KeyError: 'unknown'\\n\"\n        ],\n        \"filename\": \"test.py\",\n        \"funcName\": \"\u003cmodule\u003e\",\n        \"levelname\": \"WARNING\",\n        \"levelno\": 30,\n        \"lineno\": 18,\n        \"module\": \"test\",\n        \"msecs\": 13.036966323852539,\n        \"name\": \"root\",\n        \"pathname\": \"test.py\",\n        \"process\": 1819,\n        \"processName\": \"MainProcess\",\n        \"relativeCreated\": 18.002986907958984,\n        \"thread\": 140060726359808,\n        \"threadName\": \"MainThread\"\n    },\n    \"@message\": \"TEST\",\n    \"@source_host\": \"phoenix.spootnik.org\",\n    \"@timestamp\": \"2013-05-02T09:39:48.013158\"\n}\n~~~\n\n## Sample output for LogstashFormatterV1\nThe following keys will be found in the output JSON:\n* `@timestamp`: ISO 8601 timestamp\n* `@version`: Version of the schema\n\n~~~json\n{\"@version\": 1,\n \"account\": \"pyr\",\n \"lineno\": 1,\n \"levelno\": 30,\n \"filename\": \"test.py\",\n \"thread\": 140566036444928,\n \"@timestamp\": \"2015-03-30T09:46:23.000Z\",\n \"threadName\": \"MainThread\",\n \"relativeCreated\": 51079.52117919922,\n \"process\": 10787,\n \"source_host\": \"phoenix.spootnik.org\",\n \"processName\": \"MainProcess\",\n \"pathname\": \"test.py\",\n \"args\": [],\n \"module\": \"test\",\n \"msecs\": 999.9005794525146,\n \"created\": 1427708782.9999006,\n \"name\": \"root\",\n \"stack_info\": null,\n \"funcName\": \"\u003cmodule\u003e\",\n \"levelname\": \"WARNING\",\n \"message\": \"foo\"}\n~~~\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fulule%2Fpython-logstash-formatter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fulule%2Fpython-logstash-formatter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fulule%2Fpython-logstash-formatter/lists"}