Note: This is experimental software and has not been extensively tested in production environments!
This is a tiny utility program for applying filters to structured JSON logs. It is designed to consume output from other programs that produce logs in JSON format, such as the following:
- Go applications using the logrus library
- Node.js applications using the pino library
- Python applications using the json-logging-python library
JSON logs consist of stringified JSON object values, each value on a line terminated by a line feed character.
Note that you may need an intermediary transport middleware if your logs are not output in the format expected by this utility. Support for flexible filter expressions is planned for a future release.
The utility runs on Node.js.
Build the module using the build
script from package.json:
$ yarn run build
Run the utility by executing the main module. Optionally, you can specify command line arguments (see below).
$ node .
Use this utility as part of a UNIX-style pipe to filter out log entries produced by another process.
For example, use in conjunction with pino-pretty
to focus on interesting lines:
$ example-app | node . --min-level 50 --invalid-json=skip | npx pino-pretty
-
--help
(Optional): Print out instructions for usage. -
--min-level
(Optional): Specify minimum level as a command line argument of type integer (see above example). All lines with alevel
entry lower than the specified value will be ignored. Levels without alevel
entry will not be filtered out. -
--filter-expression
(Optional): Specify a JMESPath expression to use as a filter. The expression will be evaluated against every JSON log entry object, and only values for which the expression evaluates totrue
will pass the filter. Note that the expression must always result in a value of typeboolean
to be considered valid. Example:--filter-expression="meta.importance > `100`"
-
--invalid-json
(error
|skip
|pass
) (Optional, defaults toerror
): Specify behavior when consuming invalid JSON lines. Witherror
, the process exits with a non-zero exit code. Withskip
, the invalid line is silently filtered out and ignored. Withpass
, the invalid line passes the filter and is output to stdout as-is. -
--dry-run
(Optional): Displays filter results with colorized output: lines that pass the specified filter rules are displayed in bold green text. Lines that would be filtered out are displayed in gray text. Using this option requires stdout to be a terminal with color support (set theFORCE_COLOR
environment variable to1
to always use colored output; see details). -
--debug-print-config
(Optional): Print out resolved configuration and exit.
Run the following command to run a simple automatic test suite:
$ yarn run test