← back to Ventura Claw

scripts/emit.sh

36 lines

#!/usr/bin/env bash
# emit one event line to logs/build-events.jsonl as JSON
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
LOG="$ROOT/logs/build-events.jsonl"
mkdir -p "$(dirname "$LOG")"

# Args (all optional): --kind --phase --status --connector --label --level --msg --meta
KIND="log"; PHASE=""; STATUS=""; CONN=""; LABEL=""; LEVEL="info"; MSG=""; META=""
while [[ $# -gt 0 ]]; do
  case "$1" in
    --kind) KIND="$2"; shift 2;;
    --phase) PHASE="$2"; shift 2;;
    --status) STATUS="$2"; shift 2;;
    --connector) CONN="$2"; shift 2;;
    --label) LABEL="$2"; shift 2;;
    --level) LEVEL="$2"; shift 2;;
    --msg) MSG="$2"; shift 2;;
    --meta) META="$2"; shift 2;;
    *) shift;;
  esac
done

TS="$(date -u +%Y-%m-%dT%H:%M:%SZ)"
python3 - "$TS" "$KIND" "$PHASE" "$STATUS" "$CONN" "$LABEL" "$LEVEL" "$MSG" "$META" >> "$LOG" <<'PY'
import json, sys
ts, kind, phase, status, conn, label, level, msg, meta = sys.argv[1:]
o = {"ts": ts, "kind": kind, "level": level, "msg": msg}
if phase: o["phase"] = int(phase)
if status: o["status"] = status
if conn: o["connector"] = conn
if label: o["label"] = label
if meta: o["meta"] = meta
print(json.dumps(o))
PY