Skip to main content

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

Release files for jsonlog-cli 6.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for jsonlog-cli 6.3.0
File Size Uploaded
jsonlog-cli-6.3.0.tar.gz 11.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for jsonlog-cli 6.3.0
File Interpreter ABI Platform
jsonlog_cli-6.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 23.4 kB

Release files / jsonlog-cli-6.3.0.tar.gz

Download URL jsonlog-cli-6.3.0.tar.gz
Size 11.1 kB
Tags Source
SHA-256 checksum
How to use checksums
3689c7be242b1a24204b0d8a775c8c293df84a09eff37893c59e01c0be16172c
BLAKE2b-256 checksum
How to use checksums
c8eb40da231f28d086956bed6e9cd59d96db538d40ba0dec0ff4bfa7edffbfad
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.0.9 CPython/3.8.2 Linux/5.4.0-42-generic

Release files / jsonlog_cli-6.3.0-py3-none-any.whl

Download URL jsonlog_cli-6.3.0-py3-none-any.whl
Size 12.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1289f6cc18f867258a914a96a7ec01827c589917b8269e244b017b865b42883d
BLAKE2b-256 checksum
How to use checksums
40989aaca798ced890b46de61146d076c98f810d494a7cad924ca13b3324e107
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.0.9 CPython/3.8.2 Linux/5.4.0-42-generic

Release history Release notifications | RSS feed

This release

6.3.0 This release

2 release files

6.2.0

2 release files

6.1.3

2 release files

6.1.2

2 release files

6.1.1

2 release files

6.1.0

2 release files

6.0.1

2 release files

6.0.0

2 release files

5.2.0

2 release files

5.1.0

2 release files

5.0.0

2 release files

4.0.0

2 release files

3.1.0

2 release files

3.0.0

2 release files

2.0.0

2 release files

1.2.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page