Created
April 6, 2022 21:06
-
-
Save panzi/3e491735062d28cbaa8cce4b668e8960 to your computer and use it in GitHub Desktop.
Follow JSON logs formatted using jq. You can also pass jq options after the filename for filtering.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/bash | |
set -eo pipefail | |
RED=$(echo -e '\033[0;1;31m') | |
NORMAL=$(echo -e '\033[0m') | |
if [[ $# -lt 1 ]]; then | |
echo "usage: $0 <logfile> [jq-options...]">&2 | |
exit 1 | |
fi | |
logfile=$1 | |
shift | |
tail -f "$logfile" | while read -r line; do | |
echo "$line"|jq "$@" 2>/dev/null || echo "$RED$line$NORMAL" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment