Skip to content

Instantly share code, notes, and snippets.

@panzi
Created April 6, 2022 21:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save panzi/3e491735062d28cbaa8cce4b668e8960 to your computer and use it in GitHub Desktop.
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.
#!/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