Log Levels & When to Use Each
TL;DR
Log levels (DEBUG, INFO, WARNING, ERROR, CRITICAL) communicate severity — use the right level so alerts fire on real issues and noise doesn't mask real problems.
Explanation
Standard levels (RFC 5424 / PSR-3): EMERGENCY (system unusable), ALERT (immediate action needed), CRITICAL (component failure), ERROR (operation failed, handled), WARNING (unexpected but recovered), NOTICE (normal but significant), INFO (business events, milestones), DEBUG (developer details, queries, input). Production: log INFO and above. Development: log DEBUG and above. Rules: ERROR = operation that failed and was caught (payment declined). WARNING = degraded behaviour (cache miss, rate limited). INFO = key business events (order placed, user registered). DEBUG = everything else. CRITICAL = component down (DB, cache unavailable).
Common Misconception
✗ WARNING and ERROR are interchangeable — WARNING means 'something unusual but handled'; ERROR means 'an operation failed'. Wrong level = wrong alert thresholds.
Why It Matters
Using the right log level ensures alerts fire on real failures (ERROR/CRITICAL) and don't fire on normal degradation (WARNING) — mis-levelled logs cause alert fatigue or missed incidents.
Common Mistakes
- Logging expected user errors as ERROR — 401 Unauthorized is INFO, not ERROR.
- Not logging at INFO for key business events — hard to audit.
- DEBUG logs in production — performance and cost impact.
- CRITICAL for recoverable errors — saves CRITICAL for actual outages.
Code Examples
✗ Vulnerable
Log::error('User login failed'); // Expected behaviour — should be INFO/WARNING
Log::debug('Processing payment', $data); // In production — noise
✓ Fixed
Log::info('User login failed', ['user_email' => $email, 'reason' => 'wrong_password']);
Log::error('Payment gateway timeout', ['order_id' => $orderId, 'gateway' => 'stripe']);
Log::critical('Database connection failed', ['host' => $dbHost]);
// In config — production:
// monolog.level: info (suppresses debug)
References
Tags
🤝 Adopt this term
£79/year · your link shown here
Added
23 Mar 2026
Views
23
🤖 AI Guestbook educational data only
|
|
Last 30 days
Agents 0
No pings yet today
No pings yesterday
Amazonbot 8
Unknown AI 4
Perplexity 4
Ahrefs 2
ChatGPT 1
Majestic 1
Google 1
How they use it
crawler 19
pre-tracking 2
Related categories
⚡
DEV INTEL
Tools & Severity
🟡 Medium
⚙ Fix effort: Low
⚡ Quick Fix
Map HTTP errors: 4xx=INFO, 5xx=ERROR. Map business errors: validation=INFO, payment_failed=WARNING, payment_timeout=ERROR. Map system: component_down=CRITICAL. Disable DEBUG in production.
📦 Applies To
web
cli
queue-worker
🔗 Prerequisites
🔍 Detection Hints
Log::error|log->error
Auto-detectable:
✗ No
monolog
🤖 AI Agent
Confidence: Medium
False Positives: Medium
✗ Manual fix
Fix: Low
Context: Line