Skip to main content

JSON logstash formatter for logbook

Project description

JSON logs with logstash format for logbook

This library is provided to allow logbook logging to output log data as json objects ready to be shipped out to logstash.

This project is a fork of exoscale/python-logstash-formatter



$ pip install logbook-logstash



$ python install


Json outputs are provided by the LogstashFormatter logging formatter, for instance:

import sys

import logbook_logstash
from logbook import Logger, StreamHandler

log = Logger('testlog')

handler = StreamHandler(sys.stdout)
handler.formatter = logbook_logstash.LogstashFormatter()
handler.push_application()'My test')

You can provide extra variables, and show the exception traceback.{"account": 123, "ip": ""})"classic message for account: %s", account, extra={"account": account})

    h = {}
except:"something unexpected happened", exc_info=True)

Sample output

The following keys will be found in the output JSON:

  • @source_host: source hostname for the log

  • @timestamp: ISO 8601 timestamp

  • @message: short message for this log

  • @fields: all extra fields

  "@fields": {
      "account": "pyr",
      "args": [],
      "created": 1367480388.013037,
      "exception": [
          "Traceback (most recent call last):\n",
          "  File \"\", line 16, in <module>\n    k['unknown']\n",
          "KeyError: 'unknown'\n"
      "filename": "",
      "funcName": "<module>",
      "levelname": "WARNING",
      "levelno": 30,
      "lineno": 18,
      "module": "toto",
      "msecs": 13.036966323852539,
      "name": "root",
      "pathname": "",
      "process": 1819,
      "processName": "MainProcess",
      "relativeCreated": 18.002986907958984,
      "thread": 140060726359808,
      "threadName": "MainThread"
  "@message": "TOTO",
  "@source_host": "",
  "@timestamp": "2013-05-02T09:39:48.013158"


This project has basic tests, and uses the pytest library. Just execute the following commands in the project root.

$ pip install -r dev-requirements.txt
$ py.test

Project details

Download files

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

Source Distribution

logbook-logstash-0.1.3.tar.gz (3.7 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page