upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2026-01-09 21:41:45 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2026-01-09 21:41:45 +0000
commit6a8346441ea605248e09858d0e6b9096a1c87259 (patch)
treea24768a427f1d4b7e9adaff2b37f1385440f1c29 /scripts
parent5fed2e2f32cfb15fff042a39f3ac82abe8948ca0 (diff)
docs: add production sync testing guide and log sanitizer script
Add infrastructure for iterative debugging of sync against production data: - scripts/sanitize-logs.sh: Truncates verbose log lines for LLM analysis - docs/how-to/production-sync-testing.md: Step-by-step guide for testing sync against real relays, identifying issues, and improving logging
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/sanitize-logs.sh71
1 files changed, 71 insertions, 0 deletions
diff --git a/scripts/sanitize-logs.sh b/scripts/sanitize-logs.sh
new file mode 100755
index 0000000..123e72c
--- /dev/null
+++ b/scripts/sanitize-logs.sh
@@ -0,0 +1,71 @@
1#!/bin/bash
2# sanitize-logs.sh - Truncates verbose log lines for LLM analysis
3#
4# Usage:
5# cargo run -- [args] 2>&1 | ./scripts/sanitize-logs.sh
6# ./scripts/sanitize-logs.sh < logfile.txt
7# ./scripts/sanitize-logs.sh --head-chars 150 --tail-chars 30 < logfile.txt
8
9set -euo pipefail
10
11# Default settings
12HEAD_CHARS=100
13TAIL_CHARS=20
14MAX_LINE_LENGTH=$((HEAD_CHARS + TAIL_CHARS + 20)) # buffer for the ellipsis marker
15
16# Parse arguments
17while [[ $# -gt 0 ]]; do
18 case $1 in
19 --head-chars)
20 HEAD_CHARS="$2"
21 shift 2
22 ;;
23 --tail-chars)
24 TAIL_CHARS="$2"
25 shift 2
26 ;;
27 --max-line)
28 MAX_LINE_LENGTH="$2"
29 shift 2
30 ;;
31 -h|--help)
32 echo "Usage: $0 [OPTIONS]"
33 echo ""
34 echo "Sanitizes log output for LLM analysis by truncating long lines."
35 echo "Reads from stdin, writes to stdout."
36 echo ""
37 echo "Options:"
38 echo " --head-chars N Show first N chars of long lines (default: 100)"
39 echo " --tail-chars N Show last N chars of long lines (default: 20)"
40 echo " --max-line N Lines shorter than this are unchanged (default: head+tail+20)"
41 echo " -h, --help Show this help"
42 echo ""
43 echo "Examples:"
44 echo " cargo run -- --sync-bootstrap-relay wss://git.shakespeare.diy 2>&1 | $0"
45 echo " timeout 30s cargo run -- [args] 2>&1 | $0 > sanitized.log"
46 exit 0
47 ;;
48 *)
49 echo "Unknown option: $1" >&2
50 exit 1
51 ;;
52 esac
53done
54
55MAX_LINE_LENGTH=$((HEAD_CHARS + TAIL_CHARS + 20))
56
57# Process each line
58while IFS= read -r line; do
59 len=${#line}
60
61 if [[ $len -le $MAX_LINE_LENGTH ]]; then
62 # Short line - pass through unchanged
63 echo "$line"
64 else
65 # Long line - truncate with marker showing omitted char count
66 head="${line:0:$HEAD_CHARS}"
67 tail="${line: -$TAIL_CHARS}"
68 omitted=$((len - HEAD_CHARS - TAIL_CHARS))
69 echo "${head}...<${omitted} chars>...${tail}"
70 fi
71done