Small utility to grep logs encoded in JSON format
Installion:
cd /var/local
sudo git clone https://github.com/djeer/jsongrep.git
cd jsongrep
sudo chmod +x jsongrep.py
sudo ln -s /var/local/jsongrep/jsongrep.py /usr/bin/jsongrep
sudo chmod +x /usr/bin/jsongrep
Usage:
Print all json messages text:
python jsongrep.py user_events.log
- without installion
jsongrep user_events.log
- after installion
Print messages with filter (like grep):
jsongrep user_events.log -s some_filter_string
Print json messages after 2019-07-19T08:31:29:
jsongrep user_events.log some_filter_string -g 2019-07-19T08:31:29.169Z
Print json messages at the 2019-07-19T08:31:29 time:
jsongrep user_events.log some_filter_string -e 2019-07-19T08:31:29
Time comparing is naive, it compares python strings. It works well for all iso-like formats without need to parse dates & handle timezones and you can write time partitially like 2019-07-19T08:30
which cannot be parsed without tricks.
Handle stdin UNIX pipeline:
tail -f transfer_transactions.log | jsongrep
or with filter:
tail -f transfer_transactions.log | jsongrep -s sometext