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

Log Levels Best Practices

observability PHP 5.0+ Intermediate
debt(d5/e3/b5/t7)
d5 Detectability Operational debt — how invisible misuse is to your safety net

Closest to 'specialist tool catches it' (d5). The detection_hints list monolog, phpcs, and semgrep — these are specialist tools (a logging library, a code sniffer, and a SAST tool) that can flag patterns like everything-at-ERROR or DEBUG-in-production. This is not caught by the compiler or a default linter out-of-the-box, but semgrep rules and phpcs sniffs can be configured to detect the common code patterns listed.

e3 Effort Remediation debt — work required to fix once spotted

Closest to 'simple parameterised fix' (e3). The quick_fix describes a mapping — replace ERROR with the appropriate level (WARNING, INFO, DEBUG) per category of event. This is a pattern-replacement across call sites (e.g., changing log(ERROR, ...) to log(WARNING, ...) for ValidationExceptions), which is more than a single-line patch but contained within logging call sites rather than a cross-cutting architectural change.

b5 Burden Structural debt — long-term weight of choosing wrong

Closest to 'persistent productivity tax' (b5). The applies_to covers web, cli, and queue-worker contexts — all major PHP execution contexts. A missing or inconsistent logging strategy imposes an ongoing tax: alert fatigue slows incident response, on-call engineers develop pager-blindness, and every new feature requires a judgment call about levels with no agreed convention. This affects many work streams but doesn't fully define the system's shape.

t7 Trap Cognitive debt — how counter-intuitive correct behaviour is

Closest to 'serious trap' (t7). The misconception is explicit: developers believe logging everything at ERROR ensures nothing is missed, but the opposite is true — ERROR-level noise causes alert fatigue so real errors are ignored. This contradicts reasonable intuition ('more severe label = safer') and maps to how similar concepts work in other systems where verbosity is often considered harmless. The 'obvious' action (use ERROR to be safe) actively degrades production observability.

About DEBT scoring →

Also Known As

log level PSR-3 levels ERROR WARNING INFO DEBUG

TL;DR

Using the correct severity level — ERROR, WARNING, INFO, DEBUG — ensures alerting triggers on real issues while debug noise stays suppressible in production.

Explanation

PSR-3 defines 8 levels (emergency, alert, critical, error, warning, notice, info, debug). Practical usage: ERROR — something failed and needs attention (failed payment, unhandled exception), WARNING — something unexpected happened but recovered (cache miss, retry succeeded), INFO — normal business events (user logged in, order placed), DEBUG — detailed diagnostic data (SQL queries, API calls, method entries). Production should run at INFO or WARNING level. Never log DEBUG in production — it overwhelms aggregators and may expose sensitive data.

Common Misconception

Logging everything at ERROR ensures nothing is missed — ERROR-level noise (logging non-critical events as ERROR) causes alert fatigue; on-call teams ignore pagers when ERROR means anything.

Why It Matters

If everything is ERROR, nothing is ERROR — correct log level usage means an ERROR alert means a real problem requires attention, not routine business events.

Common Mistakes

  • Logging 404 responses as ERROR — 404 is expected user behaviour; use INFO or DEBUG.
  • Logging all exceptions as ERROR — a ValidationException is a WARNING or INFO; an uncaught exception is ERROR.
  • DEBUG logs in production — fills aggregators with noise and may log sensitive request data.
  • No logging strategy — different team members log identical events at different levels.

Code Examples

✗ Vulnerable
// Everything at ERROR — alert fatigue:
$logger->error('User ' . $userId . ' visited /about'); // This is INFO at most
$logger->error('Cache miss for key ' . $key);          // This is DEBUG
$logger->error('User provided invalid email');          // This is WARNING
// Real errors get lost in noise — on-call team ignores all alerts
✓ Fixed
// Correct levels:
$logger->debug('Cache miss', ['key' => $key]);         // Diagnostic
$logger->info('User logged in', ['user_id' => $id]);   // Business event
$logger->warning('Payment retry', ['attempt' => 2]);   // Unexpected but OK
$logger->error('Payment failed permanently', [         // Needs attention
    'order_id' => $orderId,
    'error'    => $e->getMessage(),
]);
// Production runs at INFO — DEBUG suppressed

Added 16 Mar 2026
Edited 22 Mar 2026
Views 34
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings T 0 pings F 0 pings S 2 pings S 0 pings M 0 pings T 0 pings W 2 pings T 0 pings F 0 pings S 1 ping S 0 pings M 1 ping T 0 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 0 pings F 0 pings S 2 pings S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F
No pings yet today
No pings yesterday
Amazonbot 7 ChatGPT 5 Google 4 Perplexity 3 Unknown AI 2 Ahrefs 2 Majestic 1 Qwen 1
crawler 23 crawler_json 2
DEV INTEL Tools & Severity
🟡 Medium ⚙ Fix effort: Low
⚡ Quick Fix
Use ERROR for actionable issues requiring investigation, WARNING for unexpected but handled situations, INFO for significant business events, and DEBUG for detailed flow — never log PII at any level
📦 Applies To
PHP 5.0+ web cli queue-worker
🔗 Prerequisites
🔍 Detection Hints
Everything logged at ERROR level causing alert fatigue; DEBUG logs in production; PII in log messages; no log level consistency
Auto-detectable: ✓ Yes monolog phpcs semgrep
⚠ Related Problems
🤖 AI Agent
Confidence: Medium False Positives: Medium ✓ Auto-fixable Fix: Low Context: File
CWE-532

✓ schema.org compliant