Strict Text Template Parsing
Project description
JSON log display (json-log-display)
A CLI tool for presenting JSON logging data nicely on the CLI. If there is additional non JSON data it will attempt to ignore that and use the valid JSON that is there.
It also colours the output, can pre filter, post filter, pass through or ignore non JSON data and supports an output format string.
Installation
JSON log display requires Python 3.6 or higher.
Install the pip package as follows:
$ pip install json-log-display
Use
Once installed a jld
CLI util should be available, and all you have to do is pipe logging
which has embedded JSON to it. For example:
$ tail -f /some/log/file | jld
2022-10-29T16:56:11.646734D INFO some info
2022-10-29T16:56:11.693193D DEBUG some debug
2022-10-29T16:56:11.646734D INFO more info
2022-10-29T16:56:11.646734D INFO warning alert bad
2022-10-29T16:56:11.646734D ERROR really gone wrong now
The lines will be coloured according to the level.
To change the colour of a level you can either specify a CLI argument, for
example --col info=green
, or set an environment variable, like JLD_LEVEL_INFO_COL=green
.
To change the output format use --out_format
, the default format string is
${timestamp} ${level} ${message}"
. Each ${xxxx}
is a deference to a key in
the JSON objects logged.
To change the field which is used to determine the log colour use --level_field
. For
example --level_field loglevel
.
To hide non JSON data use --no_passthrough
.
To pre filter the input (only include lines matching a given regular expression) use
--pre_filter REGEX
and provide a regular expression.
To filter the output based on the JSON data use --data_filter KEY=REGEX
.
By default JSON log display will attempt to skip junk to find valid JSON log data later
in the line. To disable this if this causes problems and your logging does not have a prefix
use --no_json_search
.
Development
A nox config is provided and Makefile. Install nox if necessary and run nox
or
run make
, which will use your default Python version and create a virtual
environment.
You can install development requirements in your current environment as follows:
$ pip install '.[dev]'
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for json_log_display-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0b462b6890d12453c241643804541a98f0d577dd46fd67598384ad709c2e4ae4 |
|
MD5 | 9a4e971f7757e615ac6c3b9a00c7449b |
|
BLAKE2b-256 | 32a498a199f1000f74398080555f545be08b70dce1d33bda671cd5857f3cd852 |