Log Levels in Structured Logs
What you'll learn: How to use standardized severity levels as queryable fields in structured logs for efficient filtering and alerting.
The Core Idea
In structured logging, log levels aren't just text prefixes—they're queryable fields with standardized values. Instead of embedding severity in a message like "[ERROR] Database connection failed", you add a level or severity field set to a standard value like ERROR. This transforms filtering from regex pattern matching into simple field queries.
The Five Standard Levels
Most systems use these severity levels (from least to most critical):
- DEBUG: Detailed diagnostic information for troubleshooting during development
- INFO: Normal operational events (user logged in, job completed)
- WARN: Potentially problematic situations that don't stop execution
- ERROR: Serious problems that require attention but the service continues
- FATAL: Critical failures that force the application to terminate
Why This Matters
When your logs are structured with "level": "ERROR" as a field, you can:
- Query all errors instantly:
level=ERROR(no regex needed) - Set up alerts that trigger only on
ERRORorFATAL - Count warnings by service:
SELECT COUNT(*) WHERE level=WARN GROUP BY service - Filter out debug noise in production without parsing text
The Analogy
Think of log levels like priority lanes at airport security. Instead of reading everyone's boarding pass to find first-class passengers (text parsing), you have separate, labeled lanes (queryable fields) that instantly categorize travelers.
Key Takeaway: Structured log levels transform severity from embedded text into queryable metadata, enabling fast filtering, precise alerting, and efficient analysis across millions of log entries.