#!/usr/bin/env bash
# Tail the experiment worker CloudWatch logs into a file while an experiment runs.
#
# Usage: ./tail_logs.sh [output_dir]

set -euo pipefail

OUTPUT_DIR="${1:-./state-$(date +%Y%m%d-%H%M%S)}"
LOG_GROUP="/ecs/claude-ecs-task-protection-experiment"

mkdir -p "${OUTPUT_DIR}"
LOG_FILE="${OUTPUT_DIR}/worker-logs.jsonl"

echo "Tailing ${LOG_GROUP} to ${LOG_FILE}"
echo "Ctrl-C to stop."

aws logs tail "${LOG_GROUP}" --follow --format short \
    | tee -a "${LOG_FILE}"
