#!/usr/bin/env bash # Tail logs for dev-mode services. # Usage: logs.sh [registry|portal|spider|all] (default: all) set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" LOG_DIR="$PROJECT_ROOT/.logs" TARGET="${1:-all}" # ── tmux mode — attach to the right window ──────────────────────────────────── if command -v tmux &>/dev/null && tmux has-session -t apix-dev 2>/dev/null; then case "$TARGET" in registry) tmux select-window -t apix-dev:registry; tmux attach -t apix-dev ;; portal) tmux select-window -t apix-dev:portal; tmux attach -t apix-dev ;; spider) tmux select-window -t apix-dev:spider; tmux attach -t apix-dev ;; all) tmux attach -t apix-dev ;; *) echo "Usage: logs.sh [registry|portal|spider|all]"; exit 1 ;; esac exit 0 fi # ── Background mode — tail log files ───────────────────────────────────────── _log() { echo "$LOG_DIR/${1}.log"; } case "$TARGET" in registry) tail -f "$(_log apix-registry)" ;; portal) tail -f "$(_log apix-portal)" ;; spider) tail -f "$(_log apix-spider)" ;; all) FILES=("$(_log apix-registry)" "$(_log apix-portal)" "$(_log apix-spider)") for f in "${FILES[@]}"; do [[ -f "$f" ]] || { echo "Log not found: $f (has dev.sh been run?)"; exit 1; } done if command -v multitail &>/dev/null; then multitail -cT ANSI "${FILES[@]}" else # Label each line with the service name using sed tail -f "${FILES[@]}" | \ awk '/==> .+apix-registry/ { svc="registry" } /==> .+apix-portal/ { svc="portal" } /==> .+apix-spider/ { svc="spider" } !/^==>/ { print "[" svc "] " $0 }' fi ;; *) echo "Usage: logs.sh [registry|portal|spider|all]"; exit 1 ;; esac