Skip to main content
Help us improve PyPI by participating in user testing. All experience levels needed!

Python formatter for working with Logstash json filters.

Project description

Python logging formatter for creating log entries in a JSON logstash-friendly format.

Supports renaming of python default logging fields to logstash friendly names (e.g: renaming asctime to @timestamp)

LogstashFormatter can receive the following arguments:

  • fmt, list or tuple containing the fields to include in each entry. Defaults to [“asctime”, “levelname”, “filename”, “funcName”, “msg”, “exc_info”].
  • datefmt, date format string to be passed to formatTime(). Defaults to ISO8601 time format.
  • rename, dictionary containing mapping of { key: new_key } to be renamed. Defaults to { “asctime”: “@timestamp” }.
  • version, version as for the @version attribute used in Logstash. Defaults to “1”.

Sample output

  "@timestamp": "2016-09-28T16:24:24,799",
  "@version": "1",
  "exc_info": null,
  "filename": "<ipython-input-21-de248ad5b09c>",
  "funcName": "<module>",
  "levelname": "INFO",
  "message": "This is a normal message to be logged"


Add LogstashFormatter as the formatter of your handler, as usual:

self.logger = logging.getLogger()
self.handler = logging.StreamHandler()

Using in Django

Include logstash formatter in your settings file:

    'formatters': {
        'logstash': {
            '()': 'logstash_formatter.LogstashFormatter',
            'format': ("asctime", "levelname", "name", "lineno", "message",
                       "pathname", "module", "funcName", "process",),
            'datefmt': '%Y-%m-%dT%H:%M:%S',
            'rename': {
                'asctime': '@timestamp',
            'version': '1'

Project details

Release history Release notifications

This version
History Node


History Node


History Node


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
logstash_python_formatter-0.1.1-py3-none-any.whl (8.8 kB) Copy SHA256 hash SHA256 Wheel py3 Oct 5, 2017
logstash-python-formatter-0.1.1.tar.gz (5.1 kB) Copy SHA256 hash SHA256 Source None Oct 5, 2017

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page