Command line tool that displays JSON logs in a human-friendly format.
Go 1.17+:
go install github.com/globocom/prettylog@latest
Go 1.16 or older:
curl https://github.com/globocom/prettylog/raw/master/install.sh | sh
Prettylog will be installed to $GOPATH/bin
. Make sure to add it to your PATH
so you can run prettylog
anywhere.
Prettylog parses log messages that contain an arbitrary number of fields and generates a nice output in the following format:
<TIMESTAMP> <LOGGER> <CALLER> <LEVEL> <MESSAGE> <FIELD1>=<VALUE> <FIELD2>=<VALUE> ...
Non-existent fields will be ignored and messages not encoded as JSON will be printed as is.
Simply pipe the stdout
of an application that outputs structured log messages into prettylog
:
app | prettylog
You might need to redirect stderr
to stdout
if the application doesn't log to the standard output:
app 2>&1 | prettylog
You can configure how Prettylog works by creating a .prettylog.yml
file either locally (per directory)
or globally (in $HOME
):
timestamp:
key: <string>
visible: <bool>
color: <list of int>
format: <string>
logger:
key: <string>
visible: <bool>
padding: <int>
color: <list of int>
caller:
key: <string>
visible: <bool>
padding: <int>
color: <list of int>
level:
key: <string>
visible: <bool>
padding: <int>
colors:
debug: <list of int>
info: <list of int>
warn: <list of int>
error: <list of int>
fatal: <list of int>
message:
key: <string>
padding: <int>
color: <list of int>
Each field has its own key and the following properties are available:
Name | Description |
---|---|
key | Field name. |
visible | Flag indicating whether the field will be printed. |
padding | Number of whitespaces that will be added to the right of the field. |
color/colors | Color attributes. Up to 3 values can be used (fg, bg and effects). More information here. |
format | (timestamp field only) Layout that will be used to print timestamp values. It must follow the rules of the time package. |
Prettylog can be used along with other command line tools. Just make sure no buffer is enabled. For instance, grep
has a --line-buffered
flag:
app | grep --line-buffered -v debug | prettylog
If the tool you want to use buffers its output and does not offer such a flag, you can try stdbuff.