Prompt
How do I alert on specific error messages in logs?
Latest observation
Oct 28, 2026
OpenAI APIWeb search: off
To alert on specific error messages in logs, the general approach is:
- Collect the logs into a system that can query them.
- Write a filter/query that matches the exact error text or pattern.
- Create an alert rule that triggers when the match count exceeds a threshold in a time window.
- Route the alert to email, Slack, PagerDuty, etc.
Common patterns
Exact match
If you want to alert when a log line contains a specific message:
"database connection failed""payment service timeout"
Partial match / keyword match
If the message may vary slightly:
ERROR AND timeout"NullPointerException"level:ERROR AND service:api
Regex match
Useful when IDs, timestamps, or dynamic values vary:
ERROR.*database connection failedPayment failed.*card declined
Example approaches by platform
Grafana Loki
LogQL example:
{app="myapp"} |= "database connection failed"
Alert on the query result being > 0 over 5 minutes.
Elasticsearch / Kibana
KQL example:
message : "database connection failed"
Alert when matching documents are found in the last N minutes.
Datadog
Log search:
service:myapp "database connection failed"
Then create a monitor on matching log count.
CloudWatch Logs
Use a metric filter:
"database connection failed"
Then create a CloudWatch alarm on the metric.
Splunk
Search:
index=myapp "database connection failed"
Create a saved search alert.
Best practices
- Alert on distinct, actionable errors, not every error line.
- Use deduplication or grouping to avoid alert storms.
- Include context in the alert: service, host, environment, sample log line.
- Consider alerting on rate spikes rather than single occurrences for noisy errors.
- Normalize logs if possible so messages are easier to match.
If you tell me your log platform
I can give you the exact query and alert setup for:
- Grafana Loki
- Elasticsearch/Kibana
- Datadog
- Splunk
- CloudWatch
- Azure Monitor
- GCP Logging