#!/bin/bash
# Simple utility to tail browser logs
# Usage: ./dss-logs.sh [error|warn|info]

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
LOG_FILE="$PROJECT_ROOT/.dss/logs/browser-logs/browser.log"
LEVEL=${1:-info}

if [ ! -f "$LOG_FILE" ]; then
    echo "Log file not found at $LOG_FILE"
    exit 1
fi

echo "Tailing browser logs (Level: $LEVEL+)... Press Ctrl+C to stop."

if [ "$LEVEL" == "error" ]; then
    tail -f "$LOG_FILE" | grep --line-buffered -i "ERROR"
elif [ "$LEVEL" == "warn" ]; then
    tail -f "$LOG_FILE" | grep --line-buffered -i -E "ERROR|WARN"
else
    tail -f "$LOG_FILE"
fi
