spatie/laravel-log-dumper
Adds an ld() helper to dump any values to your Laravel application log using Symfony VarDumper formatting. Log multiple arguments, choose or chain log levels (info/debug/error/etc.), and enable/disable logging when needed.
ld()) without modifying core Laravel structures, making it ideal for debugging-heavy applications (e.g., APIs, CLI tools, or complex business logic). It aligns with the "debugging as a utility" pattern rather than a feature.Log::channel()). Avoids reinventing the wheel for serialization.dd()/dump() disrupts execution flow. Can be selectively enabled via config (e.g., APP_DEBUG or feature flags).single for debugging, stack for production metadata) via the package’s LogDumper service provider.APP_DEBUG=true in env). Mitigation: Explicitly disable in config/logging.php or use environment checks.symfony/var-dumper version aligns with Laravel’s constraints (e.g., ^6.0 for Laravel 10).ld($user->only(['id', 'email']))).logs directory cleanup or a tool like laravel-log-manager.ld() impact on TPS. Consider async logging if I/O becomes a bottleneck.Log::debug() or Spatie\ArrayToXml\ArrayToXml::convert() for structured logs.tightenco/ziggy or spatie/laravel-activitylog for domain-specific logging.composer.json constraints.ld($failedTest->exception)).composer require spatie/laravel-log-dumper
dd() in critical paths (e.g., API endpoints) with ld() to avoid HTTP response termination.Log::extend('debug', fn($context) => ld($context))).ld($data, channel: 'audit')).Log::debug() calls remain unchanged. ld() is additive.spatie/laravel-log-dumper’s support matrix.stream, syslog, socket). For database logs, ensure the handler supports string serialization.monolog/monolog-bridge), verify the LogDumper service binds correctly.dd()/dump() usage. Replace with ld() in non-critical paths first.ld() calls in production-like environments.APP_DEBUG=false by default. Enable via feature flag for specific users/tenants.ld() usage in staging/production.ld() pattern in team runbooks (e.g., "How to Debug X").composer update + tests.ld() function via a service provider to add metadata (e.g., ld($data, ['user_id' => auth()->id()])).LogDumper to support custom formatters (e.g., JSON, YAML).dd() outputs.[DEBUG] prefix).try-catch blocks for critical paths:
try {
$result = riskyOperation();
} catch (\Throwable $e) {
ld($e, ['context' => 'operation']);
throw $e;
}
| Scenario | Recommended Action |
|---|---|
| Local dev | Use freely; no restrictions. |
| Staging | Enable via feature flag; monitor logs. |
| Production | Disable unless critical; audit logs. |
ld($data, level: 'info')) to filter severity.spatie/laravel-async-logging to offload I/O.X-Request-ID headers for traceability:
ld($data, ['request_id' => request()->header('X-Request-ID')]);
| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Unbounded log growth | Disk I/O, storage costs | Set log size limits in Monolog config. |
| Sensitive data leakage | Compliance/PII violations | Sanitize inputs (e.g., ld($user->onlySafe())). |
Production ld() calls |
Noise, performance drag | Use if (app()->isLocal()) ld($data); |
| VarDumper serialization errors | Incomplete logs | Test with edge cases (e.g., circular refs). |
| Log rotation misconfiguration | Log file bloat | Configure max_files in Monolog. |
ld() vs. Log::debug().How can I help you explore Laravel packages today?