Error Handling & Logging with Acorn
Acorn uses Laravel's logging system inside WordPress. Logs are configured per-theme in config/logging.php and coexist with WordPress's native debug.log.
When to use
- Structured logging with log levels (emergency, alert, critical, error, warning, notice, info, debug)
- Multiple log channels (daily rotating, single file, syslog, Sentry, custom)
- Exception reporting with context and stack traces
- Environment-aware logging (more verbose in dev, error-only in production)
- Integration with external monitoring (Sentry, Papertrail, Loggly)
When NOT to use
- Simple
error_log() calls for local debugging — still valid for quick traces
- WordPress-specific debug output (
WP_DEBUG_LOG = true) — native WordPress debug log is complementary, not redundant
- Performance-critical paths where per-call overhead of the logger matters — prefer conditional
WP_DEBUG gating
Prerequisites
- Acorn installed and bootstrapped
config/logging.php published (step shown below)
storage/logs/ writable by the web server user
Using the Logger
use Illuminate\Support\Facades\Log;
// Basic usage
Log::info('Order placed successfully');
Log::warning('API rate limit approaching');
Log::error('Payment gateway timeout');
// Always pass context as an array — never interpolate strings
Log::error('Payment failed', [
'order_id' => $orderId,
'gateway' => $gateway,
'amount' => $amount,
]);
// Write to a specific channel
Log::channel('errorlog')->critical('Database connection lost');
// Write to multiple channels simultaneously
Log::stack(['daily', 'errorlog'])->error('Critical failure', ['trace' => $e->getMessage()]);
Log Levels
From most to least severe — use the appropriate level:
| Level |
Use for |
emergency |
System is unusable |
alert |
Immediate action required |
critical |
Critical conditions (component failure) |
error |
Runtime errors that need attention |
warning |
Unusual conditions, not errors |
notice |
Normal but significant events |
info |
General operational messages |
debug |
Detailed debug info (dev only) |
See references/channels.md for channel config, custom channels, and WordPress debug.log bridge.
See references/structured-logging.md for context arrays, custom exceptions, and structured logging conventions.
See references/troubleshooting.md for logs not appearing, permission errors, daily rotation issues, Slack not notified.
Verification
- Write a test log entry (
Log::info('test', ['key' => 'value'])) and confirm it appears in the expected log file (e.g., storage/logs/acorn.log or the daily rotated variant).
- Verify the correct channel is being used by writing to a named channel (
Log::channel('payments')->info('test')) and checking the channel-specific log file.
Failure modes
Problem: Permission denied when writing to log file
- Cause: The web server process does not have write permissions on the
storage/logs/ directory or the log file itself.
- Fix: Fix permissions with
lando ssh -s appserver -c "chmod -R 775 /app/content/themes/{theme}/storage/logs". Ensure the storage/ directory is writable by the web server user. In Lando, this is typically handled automatically but can break after manual file operations.
Problem: Log channel not configured (driver not found)
- Cause: The channel name used in
Log::channel('name') does not exist in the channels array in config/logging.php.
- Fix: Add the missing channel definition to
config/logging.php with the appropriate driver (single, daily, errorlog, etc.) and path. Verify config/logging.php exists in your theme directory.
Escalation
- If the log disk is full or storage permissions cannot be resolved at the application level, this is an infrastructure issue -- check disk usage with
df -h and coordinate with the server administrator.
- If you need to route logs to an external service (Sentry, Datadog, Slack), add a custom channel driver in
config/logging.php or use the exception handler's reportable() method.
1---2name: superpowers-sage-acorn-logging3description: Logging in Acorn/WordPress — Log::debug(), Log::error(), Log::channel(), custom log channels, daily log files, stack channel, Slack log notifications, exception handling logging, WordPress debug.log integration, WP_DEBUG_LOG, structured logging, context arrays, monolog handlers, log levels, emergency info warning error debug, lando logs, lando ssh tail log4---56# Error Handling & Logging with Acorn78Acorn uses Laravel's logging system inside WordPress. Logs are configured per-theme in `config/logging.php` and coexist with WordPress's native `debug.log`.910## When to use1112- Structured logging with log levels (emergency, alert, critical, error, warning, notice, info, debug)13- Multiple log channels (daily rotating, single file, syslog, Sentry, custom)14- Exception reporting with context and stack traces15- Environment-aware logging (more verbose in dev, error-only in production)16- Integration with external monitoring (Sentry, Papertrail, Loggly)1718## When NOT to use1920- Simple `error_log()` calls for local debugging — still valid for quick traces21- WordPress-specific debug output (`WP_DEBUG_LOG = true`) — native WordPress debug log is complementary, not redundant22- Performance-critical paths where per-call overhead of the logger matters — prefer conditional `WP_DEBUG` gating2324## Prerequisites2526- Acorn installed and bootstrapped27- `config/logging.php` published (step shown below)28- `storage/logs/` writable by the web server user2930## Using the Logger3132```php33use Illuminate\Support\Facades\Log;3435// Basic usage36Log::info('Order placed successfully');37Log::warning('API rate limit approaching');38Log::error('Payment gateway timeout');3940// Always pass context as an array — never interpolate strings41Log::error('Payment failed', [42 'order_id' => $orderId,43 'gateway' => $gateway,44 'amount' => $amount,45]);4647// Write to a specific channel48Log::channel('errorlog')->critical('Database connection lost');4950// Write to multiple channels simultaneously51Log::stack(['daily', 'errorlog'])->error('Critical failure', ['trace' => $e->getMessage()]);52```5354## Log Levels5556From most to least severe — use the appropriate level:5758| Level | Use for |59|---|---|60| `emergency` | System is unusable |61| `alert` | Immediate action required |62| `critical` | Critical conditions (component failure) |63| `error` | Runtime errors that need attention |64| `warning` | Unusual conditions, not errors |65| `notice` | Normal but significant events |66| `info` | General operational messages |67| `debug` | Detailed debug info (dev only) |6869See [`references/channels.md`](references/channels.md) for channel config, custom channels, and WordPress debug.log bridge.70See [`references/structured-logging.md`](references/structured-logging.md) for context arrays, custom exceptions, and structured logging conventions.71See [`references/troubleshooting.md`](references/troubleshooting.md) for logs not appearing, permission errors, daily rotation issues, Slack not notified.7273## Verification7475- Write a test log entry (`Log::info('test', ['key' => 'value'])`) and confirm it appears in the expected log file (e.g., `storage/logs/acorn.log` or the daily rotated variant).76- Verify the correct channel is being used by writing to a named channel (`Log::channel('payments')->info('test')`) and checking the channel-specific log file.7778## Failure modes7980### Problem: Permission denied when writing to log file81- **Cause:** The web server process does not have write permissions on the `storage/logs/` directory or the log file itself.82- **Fix:** Fix permissions with `lando ssh -s appserver -c "chmod -R 775 /app/content/themes/{theme}/storage/logs"`. Ensure the `storage/` directory is writable by the web server user. In Lando, this is typically handled automatically but can break after manual file operations.8384### Problem: Log channel not configured (driver not found)85- **Cause:** The channel name used in `Log::channel('name')` does not exist in the `channels` array in `config/logging.php`.86- **Fix:** Add the missing channel definition to `config/logging.php` with the appropriate driver (`single`, `daily`, `errorlog`, etc.) and path. Verify `config/logging.php` exists in your theme directory.8788## Escalation8990- If the log disk is full or storage permissions cannot be resolved at the application level, this is an infrastructure issue -- check disk usage with `df -h` and coordinate with the server administrator.91- If you need to route logs to an external service (Sentry, Datadog, Slack), add a custom channel driver in `config/logging.php` or use the exception handler's `reportable()` method.