| name | log-analysis |
| description | Search and analyze application logs: error frequency, grep/jq patterns, JSON structured logs, log tailing, anomaly detection. Trigger: when searching logs, analyzing log files, filtering log output, JSON log analysis, log patterns, jq logs |
| version | 1 |
| argument-hint | [log-file or pattern] |
| allowed-tools | ["bash","read","grep","glob"] |
Log Analysis
You are now operating in log analysis mode.
Search by Log Level
grep '"level":"error"' app.log
grep -i '"level":"error"' app.log
grep -E '"level":"(error|warn)"' app.log
jq 'select(.level == "error")' app.log
tail -f app.log | grep '"level":"error"'
tail -f app.log | jq -c 'select(.level == "error")'
Search by Time Range
grep '2026-03-10T14:' app.log
awk '/2026-03-10T14:[0-9][0-9]/' app.log
CUTOFF=$(date -u -v-30M '+%Y-%m-%dT%H:%M' 2>/dev/null || date -u --date='30 minutes ago' '+%Y-%m-%dT%H:%M')
jq --arg t "$CUTOFF" 'select(.time >= $t)' app.log
Search by Pattern
grep -E 'timeout|connection refused|deadline exceeded' app.log
grep -C 3 'panic:' app.log
grep -n 'ERROR' app.log
grep -r '"level":"error"' ./logs/
grep -c '"level":"error"' app.log
JSON Log Processing with jq
tail -100 app.log | jq 'select(.level == "error")'
jq '{time, level, msg, error}' app.log
jq -r 'select(.level == "error") | "\(.time) \(.msg)"' app.log
jq -r '.level' app.log | sort | uniq -c | sort -rn
jq -r 'select(.level == "error") | .msg' app.log | sort | uniq -c | sort -rn | head -20
Error Frequency Analysis
jq -r 'select(.level == "error") | .time[0:16]' app.log | sort | uniq -c
jq -r 'select(.level == "error") | .time[0:13]' app.log | sort | uniq -c
jq -r 'select(.level == "error") | .path' app.log | sort | uniq -c | sort -rn | head -10
Request Latency / Performance
jq 'select(.duration_ms != null) | .duration_ms' app.log | sort -n
jq '.duration_ms' app.log | sort -n | awk '
BEGIN { n=0 }
{ a[n++]=$1 }
END {
print "p50:", a[int(n*0.50)]
print "p95:", a[int(n*0.95)]
print "p99:", a[int(n*0.99)]
print "max:", a[n-1]
}'
jq 'select(.duration_ms > 1000)' app.log | jq -r '"SLOW: \(.duration_ms)ms \(.path // "")"'
Anomaly Detection
NOW=$(date +%s)
FIVE_MIN_AGO=$(( NOW - 300 ))
TEN_MIN_AGO=$(( NOW - 600 ))
RECENT=$(jq --argjson t "$FIVE_MIN_AGO" 'select(.ts > $t and .level == "error")' app.log | wc -l)
PREVIOUS=$(jq --argjson t1 "$TEN_MIN_AGO" --argjson t2 "$FIVE_MIN_AGO" 'select(.ts > $t1 and .ts <= $t2 and .level == "error")' app.log | wc -l)
echo "Recent errors: $RECENT, Previous period: $PREVIOUS"
Tailing and Live Monitoring
tail -f app.log | jq -c '.'
tail -f app.log | jq -c 'select(.level == "error") | {time, msg, error}'
tail -f app.log | grep -E 'error|panic|fatal'
journalctl -u harnessd -f
journalctl -u harnessd --since "10 minutes ago" | grep -i error
Correlation: Trace IDs
grep '"trace_id":"abc123"' app.log
jq 'select(.trace_id == "abc123")' app.log | jq -r '"\(.time) \(.level) \(.msg)"'
Common Log Formats
awk '{print $9}' access.log | sort | uniq -c | sort -rn | head
grep '^ERROR' app.log
grep -E '^(ERROR|WARN)' app.log
grep 'level=ERROR' app.log