Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions docker-tail
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,17 @@ for i in "${containers[@]}"; do
# created a fixed length prefix containing the container name for each line of log output
line_prefix=$(printf "|%-13s | " "$i")

# fork and spawn `docker logs -f`, feeding output through sed to add our prefix and colors
(docker logs --tail=10 --timestamps -f "$i" 2>&1 \
| sed "s/^/$color$line_prefix/; s/$/$RESET_COLOR/") &
# fork and spawn `docker logs -f` with automatic reconnection, feeding output through sed to add our prefix and colors
(
while true; do
if docker ps --format '{{.Names}}' | grep -q "^${i}$"; then
docker logs --tail=10 --timestamps -f "$i" 2>&1 \
| sed "s/^/$color$line_prefix/; s/$/$RESET_COLOR/"
fi
# wait a bit before attempting to reconnect
sleep 2
done
) &

cnt=$((cnt + 1))
done
Expand Down