Last active
February 13, 2025 15:01
-
-
Save pads/863653524af27a5fb6d537e90f95779b to your computer and use it in GitHub Desktop.
Helper script to pretty print and filter docker JSON logs output
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
logs_help () { | |
echo "Usage:" | |
echo "logs <container name> <jq expression>" | |
} | |
CONTAINER=$1 | |
FILTER="$2" | |
if [ ! $# -eq 1 ]; then | |
logs_help | |
else | |
# First argument passed to jq is to filter out log lines that are not valid JSON | |
docker-compose logs -f $1 --no-log-prefix 2>&1 | jq -R "fromjson? | $FILTER" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example to print everything:
logs api .
Example to get only the
msg
from the logs:Example to get messages containing text:
logs api 'select(.msg | contains("THING"))'