CLI tool to read Graylog
Extended Log Format (GELF) log lines from stdin, such as:
{"version":"1.1","host":"my-server","short_message":"Starting server","timestamp":1555690413.839,"level":6,"_app":"my-app","_logger":"api","_port":"3000"}
{"version":"1.1","host":"my-server","short_message":"Listening for requests","timestamp":1555690413.903,"level":6,"_app":"my-app","_logger":"api","_endpoint":"locahost:3000/v1"}
{"version":"1.1","host":"my-server","short_message":"Request received","timestamp":155569049.540,"level":6,"_app":"my-app","_logger":"api","_method":"GET","_path":"/todos/1","_request_id":"0c4c165d"}
{"version":"1.1","host":"my-server","short_message":"Response","full_message":"{\n\t\"user_id\": 1,\n\t\"id\": 1,\n\t\"title\": \"fix /users/:id/todos route\",\n\t\"completed\": false\n}","timestamp":155569049.584,"level":7,"_app":"my-app","_logger":"api","_request_id":"0c4c165d","_status":200}
{"version":"1.1","host":"my-server","short_message":"Request received","timestamp":155569349.236,"level":6,"_app":"my-app","_logger":"api","_method":"GET","_path":"/users/1/todos","_request_id":"0c4c165d"}
{"version":"1.1","host":"my-server","short_message":"Unexpected error","full_message":"runtime error: index out of range\ngoroutine 1 [running]:\nmain.main()\n\t/app/api/main.go: 9 +0x20","timestamp":155569349.563,"level":3,"_app":"my-app","_logger":"api","_request_id":"0c4c165d"}
{"version":"1.1","host":"my-server","short_message":"Server shutting down","timestamp":155569349.571,"level":4,"_app":"my-app","_logger":"api"}
And pretty-print them to stdout like:
You can install gelf-pretty using one of the following options:
- Pre-built packages for macOS and Linux (easiest);
- Pre-compiled binaries for macOS, Linux and Windows;
- From source.
Install via Homebrew:
$ brew install joaodrp/tap/gelf-prettyInstall via Snapcraft:
$ snap install gelf-prettyYou can also download .deb or .rpm packages from the releases
page and install with dpkg -i or rpm -i respectively.
Download the correct archive for your platform from the releases
page and extract the
gelf-pretty binary to a directory included in your $PATH/Path.
$ go install github.com/joaodrp/gelf-pretty@latestMake sure that $GOPATH/bin is in your $PATH.
GELF messages are pretty-printed in the following format:
[<timestamp>] <level>: <_app>/<_logger> on <host>: <short_message> <_*>=<value>\n
<full_message>
-
<timestamp>is the value of the standard GELF unixtimestampfield, formatted as2006-01-02 15:04:05.000; -
<level>is the value of the standard GELF loglevelfield, formatted in a human-readable form (e.g.DEBUGinstead of7); -
<_app>is an optional reserved additional field. It can be used to identify the name of the application emitting the logs. If not provided, the forward slash that follows it is omitted; -
<_logger>is an optional reserved additional field. It can be used to identify the specific application module or logger instance that is emitting a given log line; -
<host>is the value of the standard GELFhostfield; -
<short_message>is the value of the standard GELFshort_messagefield; -
<_*>=<value>is any number of GELF additional fields (_*), formatted askey=valuepairs separated by a whitespace. The keys leading underscore is omitted for readability; -
<full_message>is the value of the standard GELFfull_messagefield (usually used for exception backtraces). It is preceded by a new line and indented with four spaces.
gelf-pretty automatically detects if the output stream is a TTY or not. If
(and only if) it is, the output will be formatted by default with ANSI colors
for improved readability.
To pretty-print GELF logs from your application simply pipe its output to
gelf-pretty:
$ app | gelf-prettyRun gelf-pretty --help for a list of available options:
$ gelf-pretty --help
Usage of gelf-pretty:
--no-color
Disable color output
--version
Show version informationIf your application writes to the stderr stream you will need to pipe it along
with stdout:
$ app 2>&1 | gelf-prettyTo disable colored output (even if the output stream is a TTY) use the
--no-color option:
$ app | gelf-pretty --no-colorgelf-pretty validates each input line. If a line (delimited by \n) is not a
valid JSON string or is invalid according to the GELF
specification,
gelf-pretty will simply echo it back to the stdout without any modification
(silently, with no error messages).
If you believe that your log messages are valid, please open a new issue and let us know.
This project adheres to the Contributor Covenant code of conduct. By participating, you are expected to uphold this code. Please refer to our contributing guide for further information.
