Overview
Architecture and design philosophy of WPZylos Logger.
Philosophy
WPZylos Logger provides a PSR-3 compliant logging solution designed specifically for WordPress plugins. It enables structured logging with context support while integrating with WordPress debug tools.
Architecture
┌─────────────────────────────────────────────────────────────┐
| Logger |
+--───────────────────────────────────────────────────────────┤
| |
| ┌─────────────┐ ┌─────────────┐ ┌─────────────────────┐ |
| | Log Levels | | Min Level | | Formatters | |
| | (PSR-3) | | (Filter) | | (Interpolation) | |
| +--────┬──────┘ +--────┬──────┘ +--────────┬──────────┘ |
| | | | |
| ▼ ▼ ▼ |
| ┌─────────────────────────────────────────────────────┐ |
| | Log Output | |
| | (File, error_log) | |
| +--───────────────────────────────────────────────────┘ |
| |
+--───────────────────────────────────────────────────────────┘
PSR-3 Log Levels
| Level | Constant | Description |
|---|---|---|
| Emergency | LogLevel::EMERGENCY | System is unusable |
| Alert | LogLevel::ALERT | Immediate action required |
| Critical | LogLevel::CRITICAL | Critical conditions |
| Error | LogLevel::ERROR | Error conditions |
| Warning | LogLevel::WARNING | Warning conditions |
| Notice | LogLevel::NOTICE | Normal but significant |
| Info | LogLevel::INFO | Informational messages |
| Debug | LogLevel::DEBUG | Debug-level messages |
Key Concepts
Structured Logging
Log messages include structured context data:
$logger->info('Order placed', [
'order_id' => 123,
'user_id' => 456,
'total' => 99.99,
]);
Channels
Different output destinations for logs:
- File — Write to daily log files
- error_log — PHP error_log function (when WP_DEBUG enabled)
vs Native PHP Logging
| Feature | error_log | WPZylos Logger |
|---|---|---|
| Levels | Bad: | Good: |
| Context | Bad: | Good: |
| PSR-3 | Bad: | Good: |
| Formatters | Bad: | Good: |
| Plugin-aware | Bad: | Good: |