Skip to main content

Convert structured JSON logs to human-readable output

Project description

jsonlog-cli

A human readable formatter for JSON logs.

It's built for use with jsonlog but will work well with any log format that uses line delimited JSON.

Example output

Usage

See jsonlog --help for all options.

Key-value mode

Pass a file as the only argument to jsonlog, or read from STDIN by default.

jsonlog kv docs/example.log
python docs/example.py | jsonlog kv
cat docs/example.log | jsonlog

Only show the timestamp and message fields:

jsonlog kv --key timestamp --key message docs/example.log

Configure the keys of multiline values you want to display (can be specified multiple times, and defaults to the traceback key.)

jsonlog kv --key timestamp --key message --multiline-key traceback docs/example.log

Configure the key to extract and use as the records level, controlling the colour each line is printed in (defaults to the level key).

jsonlog kv --level-key level --key timestamp --key message --multiline-key traceback docs/example.log

Template mode

Only show the timestamp and message fields:

jsonlog template --format "{timestamp} {message}" docs/example.log

Also show a multiline key when it's present:

jsonlog template --format "{timestamp} {message}" --multiline-key traceback docs/example.log

Configuration

Named "patterns" are supported as a way of collecting a set of options for jsonlog's key-value and template modes. If ~/.config/jsonlog/config.json exists, it will be loaded at startup. All fields should be optional.

The example configuration file below creates patterns named basic and comprehensive for the key-value and template modes. The patterns will each show the timestamp and message fields of incoming logs. The patterns named comprehensive override all fields, setting their their default values.

Creating a pattern named default will set the default options used if no pattern is specified. Command line options always override options from the application's default configuration, the configuration file and the selected pattern.

{
  "keyvalues": {
    "basic": {
      "priority_keys": ["timestamp", "message"]
    },
    "comprehensive": {
      "level_key": "level",
      "multiline_json": false,
      "multiline_keys": [],
      "priority_keys": [],
      "removed_keys": []
    }
  },
  "templates": {
    "basic": {
      "format": "{timestamp} {message}"
    },
    "comprehensive": {
      "level_key": "level",
      "multiline_json": false,
      "multiline_keys": [],
      "format": "{timestamp} {message}" 
    }
  }
}

The multiline_json option will parse incoming data using a buffer. This is rarely useful, but some applications (e.g. ElasticSearch) output JSON split across multiple lines. Incoming data will be buffered until the whole buffer can be parsed as JSON or a new line starts with {. Incoming lines that can be immediately parsed as JSON are not buffered (flushing the buffer first).

Debugging

The jsonlog CLI has some flags that are useful when debugging. The following will print internal logs as JSON to STDERR.

jsonlog --log-path=- --log-level=debug kv ...

Authors

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

jsonlog-cli-6.1.0.tar.gz (11.3 kB view details)

Uploaded Source

Built Distribution

jsonlog_cli-6.1.0-py3-none-any.whl (12.5 kB view details)

Uploaded Python 3

File details

Details for the file jsonlog-cli-6.1.0.tar.gz.

File metadata

  • Download URL: jsonlog-cli-6.1.0.tar.gz
  • Upload date:
  • Size: 11.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.5 CPython/3.8.2 Linux/5.4.0-40-generic

File hashes

Hashes for jsonlog-cli-6.1.0.tar.gz
Algorithm Hash digest
SHA256 bc4608b399cf466ee9b46320ef84c5a15dbae375f8d6cd29f7aead7fd4f5865c
MD5 fef9d51ef4ac30df2f99b22c2527abcd
BLAKE2b-256 0cc2b1209c9d6896aabb9786d358e3f7c9806239b9931f57803b8c2b9061e0d0

See more details on using hashes here.

File details

Details for the file jsonlog_cli-6.1.0-py3-none-any.whl.

File metadata

  • Download URL: jsonlog_cli-6.1.0-py3-none-any.whl
  • Upload date:
  • Size: 12.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.5 CPython/3.8.2 Linux/5.4.0-40-generic

File hashes

Hashes for jsonlog_cli-6.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a882f4118d6bc6f8797e12eca3b74aa2e9ce0335c84a5c6b1b0c681b3ca626a8
MD5 39c8c90a292aacd3439119b38a6ebf59
BLAKE2b-256 81d0ccc362d9134d6b3c00f590f59174358c747bde624956453123a48951e1cc

See more details on using hashes here.

Supported by

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