Log Analyzer
Parses structured (JSON, logfmt) and unstructured application logs to identify error trends, anomaly spikes, performance degradation patterns, and actionable insights — with a focus on operational intelligence and incident investigation.
When to Use
- User shares log output and asks "what went wrong?"
- Investigating a production incident or outage
- High error rates are reported and root cause is unknown
- User asks to "find errors in these logs" or "summarize what happened"
- Anomaly detection is needed (spike in error rate, latency increase)
- Security events need to be identified (auth failures, unusual access patterns)
Process
Identify the log format:
- Structured JSON: parse fields like
level, message, timestamp, error, trace_id
- logfmt:
key=value pairs, parse as structured
- Apache/Nginx access logs:
$remote_addr - - [$time] "$request" $status $bytes
- Syslog / journald:
<priority>timestamp host process[pid]: message
- Unstructured: apply pattern matching and regex extraction
Establish the time range and baseline:
- Identify the earliest and latest timestamps in the log
- Count total log volume per minute/hour to establish baseline
- Note any obvious time-based patterns (spikes, gaps, silent periods)
Extract and count errors by type:
- Group by error message, exception class, or HTTP status code
- Count occurrences and calculate error rate (errors / total requests or events)
- Rank error types by frequency
- Flag error rate increases compared to prior baseline period
Identify anomaly spikes:
- Time windows with >2x normal error rate
- Sudden appearance of a new error type
- Latency percentiles (P99, P95) exceeding thresholds
- Specific user IDs, IPs, or services appearing disproportionately
Trace correlated events:
- Group log lines by
trace_id, request_id, or session_id to reconstruct request flows
- Find the sequence of events leading to an error
- Identify which service or function in the call chain first logged the error
Detect security events:
- Repeated authentication failures from the same IP (brute force)
- Access to sensitive paths (admin,
.env, config files)
- Unusual HTTP methods or oversized request payloads
- Token/session reuse anomalies
Produce a structured summary with timeline, top errors, and recommended actions.
Output Format
## Log Analysis Report
**Log range:** 2024-03-15 09:00 UTC → 2024-03-15 11:30 UTC (2.5 hours)
**Total events:** 284,312
**Error rate:** 3.2% (baseline: 0.4%) — **8x elevated**
---
### Timeline
- `09:00–09:47` — Normal traffic (~1,800 req/min, 0.4% errors)
- `09:47` — 🔴 Error spike begins: `ConnectionError: DB connection pool exhausted`
- `09:47–10:15` — 28 minutes of degraded service (18% error rate)
- `10:15` — Error rate returns to baseline (likely pool expansion or traffic drop)
- `10:15–11:30` — Normal operations
---
### Top Errors (09:47–10:15 window)
| Rank | Error | Count | % of errors |
|------|-------|-------|-------------|
| 1 | `ConnectionError: DB pool exhausted` | 2,847 | 64% |
| 2 | `Timeout: downstream /api/inventory 30s` | 891 | 20% |
| 3 | `ValidationError: missing field 'quantity'` | 412 | 9% |
---
### Root Cause Analysis
The DB connection pool exhaustion at 09:47 correlates with a deployment at 09:45
(seen in logs: `[INFO] New deployment: v2.3.1`). The new version likely introduced
a connection leak or reduced the pool size. The inventory timeout errors are
a cascade effect — DB slowness caused the inventory service to time out,
generating secondary errors.
---
### Recommended Actions
1. Roll back to v2.3.0 or hot-patch the connection pool configuration
2. Add alerting on DB pool exhaustion (currently no alert exists)
3. Investigate `ValidationError` on `quantity` field — unrelated to the incident
but represents a pre-existing issue requiring a separate fix
Examples
Example Input
2024-03-15T09:47:12Z ERROR ConnectionError: DB connection pool exhausted at getUser (db.js:45)
2024-03-15T09:47:13Z ERROR ConnectionError: DB connection pool exhausted at getUser (db.js:45)
2024-03-15T09:47:13Z WARN Request timeout after 30s: GET /api/orders/123
[... 3000 more similar lines ...]
2024-03-15T10:15:02Z INFO Health check passed. DB connections: 5/20 available
Example Output
28-minute incident starting at 09:47 UTC.
Primary cause: DB connection pool exhaustion (64% of errors).
Secondary cascade: /api/orders timeouts due to DB unavailability (20%).
Incident resolved at ~10:15 UTC when pool recovered.
Recommend: add pool monitoring alert, review recent deployment for connection leaks.
Boundaries
- Do NOT attempt to access live log streams or external logging services — only analyze log content provided in the conversation.
- Do NOT reveal PII found in logs (email addresses, user IDs, IP addresses) beyond what is necessary for the analysis — generalize where possible.
- If logs are truncated or sampled, note that findings may not represent the complete picture.
- Do NOT make definitive root cause claims without corroborating evidence — use qualified language ("likely", "correlates with").
- If log volume is too large to fully analyze in context, prioritize the error-dense time windows and note the sampling approach.
- Do NOT generate queries against logging services (Splunk, Datadog, Loki) unless the user provides the query interface and credentials are not required.
1---2name: log-analyzer3description: Parses structured or unstructured application logs to surface error trends, anomaly spikes, and actionable insights. Invoke when asked to analyze logs, find errors in log output, investigate a production incident, identify patterns in log data, or summarize what happened in a time window.4---56# Log Analyzer78Parses structured (JSON, logfmt) and unstructured application logs to identify error trends, anomaly spikes, performance degradation patterns, and actionable insights — with a focus on operational intelligence and incident investigation.910## When to Use1112- User shares log output and asks "what went wrong?"13- Investigating a production incident or outage14- High error rates are reported and root cause is unknown15- User asks to "find errors in these logs" or "summarize what happened"16- Anomaly detection is needed (spike in error rate, latency increase)17- Security events need to be identified (auth failures, unusual access patterns)1819## Process20211. **Identify the log format**:22 - **Structured JSON**: parse fields like `level`, `message`, `timestamp`, `error`, `trace_id`23 - **logfmt**: `key=value` pairs, parse as structured24 - **Apache/Nginx access logs**: `$remote_addr - - [$time] "$request" $status $bytes`25 - **Syslog / journald**: `<priority>timestamp host process[pid]: message`26 - **Unstructured**: apply pattern matching and regex extraction27282. **Establish the time range and baseline**:29 - Identify the earliest and latest timestamps in the log30 - Count total log volume per minute/hour to establish baseline31 - Note any obvious time-based patterns (spikes, gaps, silent periods)32333. **Extract and count errors by type**:34 - Group by error message, exception class, or HTTP status code35 - Count occurrences and calculate error rate (errors / total requests or events)36 - Rank error types by frequency37 - Flag error rate increases compared to prior baseline period38394. **Identify anomaly spikes**:40 - Time windows with >2x normal error rate41 - Sudden appearance of a new error type42 - Latency percentiles (P99, P95) exceeding thresholds43 - Specific user IDs, IPs, or services appearing disproportionately44455. **Trace correlated events**:46 - Group log lines by `trace_id`, `request_id`, or `session_id` to reconstruct request flows47 - Find the sequence of events leading to an error48 - Identify which service or function in the call chain first logged the error49506. **Detect security events**:51 - Repeated authentication failures from the same IP (brute force)52 - Access to sensitive paths (admin, `.env`, config files)53 - Unusual HTTP methods or oversized request payloads54 - Token/session reuse anomalies55567. **Produce a structured summary** with timeline, top errors, and recommended actions.5758## Output Format5960```61## Log Analysis Report6263**Log range:** 2024-03-15 09:00 UTC → 2024-03-15 11:30 UTC (2.5 hours)64**Total events:** 284,31265**Error rate:** 3.2% (baseline: 0.4%) — **8x elevated**6667---6869### Timeline70- `09:00–09:47` — Normal traffic (~1,800 req/min, 0.4% errors)71- `09:47` — 🔴 Error spike begins: `ConnectionError: DB connection pool exhausted`72- `09:47–10:15` — 28 minutes of degraded service (18% error rate)73- `10:15` — Error rate returns to baseline (likely pool expansion or traffic drop)74- `10:15–11:30` — Normal operations7576---7778### Top Errors (09:47–10:15 window)7980| Rank | Error | Count | % of errors |81|------|-------|-------|-------------|82| 1 | `ConnectionError: DB pool exhausted` | 2,847 | 64% |83| 2 | `Timeout: downstream /api/inventory 30s` | 891 | 20% |84| 3 | `ValidationError: missing field 'quantity'` | 412 | 9% |8586---8788### Root Cause Analysis89The DB connection pool exhaustion at 09:47 correlates with a deployment at 09:4590(seen in logs: `[INFO] New deployment: v2.3.1`). The new version likely introduced91a connection leak or reduced the pool size. The inventory timeout errors are92a cascade effect — DB slowness caused the inventory service to time out,93generating secondary errors.9495---9697### Recommended Actions981. Roll back to v2.3.0 or hot-patch the connection pool configuration992. Add alerting on DB pool exhaustion (currently no alert exists)1003. Investigate `ValidationError` on `quantity` field — unrelated to the incident101 but represents a pre-existing issue requiring a separate fix102```103104## Examples105106### Example Input107```1082024-03-15T09:47:12Z ERROR ConnectionError: DB connection pool exhausted at getUser (db.js:45)1092024-03-15T09:47:13Z ERROR ConnectionError: DB connection pool exhausted at getUser (db.js:45)1102024-03-15T09:47:13Z WARN Request timeout after 30s: GET /api/orders/123111[... 3000 more similar lines ...]1122024-03-15T10:15:02Z INFO Health check passed. DB connections: 5/20 available113```114115### Example Output116```11728-minute incident starting at 09:47 UTC.118Primary cause: DB connection pool exhaustion (64% of errors).119Secondary cascade: /api/orders timeouts due to DB unavailability (20%).120121Incident resolved at ~10:15 UTC when pool recovered.122Recommend: add pool monitoring alert, review recent deployment for connection leaks.123```124125## Boundaries126127- Do NOT attempt to access live log streams or external logging services — only analyze log content provided in the conversation.128- Do NOT reveal PII found in logs (email addresses, user IDs, IP addresses) beyond what is necessary for the analysis — generalize where possible.129- If logs are truncated or sampled, note that findings may not represent the complete picture.130- Do NOT make definitive root cause claims without corroborating evidence — use qualified language ("likely", "correlates with").131- If log volume is too large to fully analyze in context, prioritize the error-dense time windows and note the sampling approach.132- Do NOT generate queries against logging services (Splunk, Datadog, Loki) unless the user provides the query interface and credentials are not required.