← CodeClarityLab Home
Browse by Category
+ added · updated 7d
← Back to glossary

Log Levels & When to Use Each

observability Beginner

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)

Added 23 Mar 2026
Views 23
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
2 pings W 0 pings T 2 pings F 0 pings S 1 ping S 0 pings M 0 pings T 0 pings W 0 pings T 1 ping F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 2 pings F 0 pings S 0 pings S 0 pings M 0 pings T 1 ping W 0 pings T 1 ping F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T
No pings yet today
No pings yesterday
Amazonbot 8 Unknown AI 4 Perplexity 4 Ahrefs 2 ChatGPT 1 Majestic 1 Google 1
crawler 19 pre-tracking 2
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

✓ schema.org compliant