Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Log Dumper Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Lightweight & Non-Intrusive: The package introduces a single global function (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.
  • Symfony VarDumper Integration: Leverages a battle-tested library for structured dumping, ensuring consistency with Laravel’s existing logging ecosystem (e.g., Log::channel()). Avoids reinventing the wheel for serialization.
  • Contextual Logging: Useful in microservices, event-driven architectures, or long-running processes where traditional dd()/dump() disrupts execution flow. Can be selectively enabled via config (e.g., APP_DEBUG or feature flags).

Integration Feasibility

  • Zero Configuration: Works out-of-the-box with Laravel’s default logging setup (Monolog). No database or external dependencies required.
  • Channel Flexibility: Can be extended to log to specific Monolog channels (e.g., single for debugging, stack for production metadata) via the package’s LogDumper service provider.
  • Performance Impact: Minimal overhead during development; negligible in production if disabled. Risk: Unbounded log growth if misused (e.g., dumping large objects in loops).

Technical Risk

  • Log Bloat: High-volume dumps (e.g., large arrays, nested objects) may inflate log files or slow down I/O-bound systems. Mitigation: Add size limits or rate-limiting via middleware.
  • Production Leakage: Accidental inclusion in production builds (e.g., via APP_DEBUG=true in env). Mitigation: Explicitly disable in config/logging.php or use environment checks.
  • VarDumper Quirks: Complex objects (e.g., closures, resources) may not serialize predictably. Test with domain-specific data models.
  • Dependency Conflicts: None critical, but ensure symfony/var-dumper version aligns with Laravel’s constraints (e.g., ^6.0 for Laravel 10).

Key Questions

  1. Use Case Clarity:
    • Is this for development-only debugging, or runtime monitoring (e.g., logging failed payments)?
    • Will dumps include sensitive data (PII, tokens)? If so, implement sanitization (e.g., ld($user->only(['id', 'email']))).
  2. Log Management:
    • How will logs be rotated/archived? The package doesn’t handle retention—pair with Laravel’s logs directory cleanup or a tool like laravel-log-manager.
    • Are there log aggregation tools (e.g., ELK, Datadog) where dumps should be structured for querying?
  3. Performance:
    • For high-throughput systems, test ld() impact on TPS. Consider async logging if I/O becomes a bottleneck.
  4. Alternatives:
    • Compare with native Log::debug() or Spatie\ArrayToXml\ArrayToXml::convert() for structured logs.
    • Evaluate tightenco/ziggy or spatie/laravel-activitylog for domain-specific logging.

Integration Approach

Stack Fit

  • Laravel Ecosystem: Native compatibility with Monolog, Laravel’s logging facade, and service containers. No polyfills or shims required.
  • PHP Versions: Supports PHP 8.1+ (per Spatie’s recent updates). Verify compatibility with your composer.json constraints.
  • Tooling:
    • IDE Integration: Works seamlessly with PHPStorm/Xdebug for local debugging.
    • CI/CD: Useful for logging test failures or debug context in pipelines (e.g., ld($failedTest->exception)).

Migration Path

  1. Installation:
    composer require spatie/laravel-log-dumper
    
    • No publisher or config required for basic usage.
  2. Adoption Phases:
    • Phase 1: Replace dd() in critical paths (e.g., API endpoints) with ld() to avoid HTTP response termination.
    • Phase 2: Standardize usage via a custom macro (e.g., Log::extend('debug', fn($context) => ld($context))).
    • Phase 3: Extend to custom channels (e.g., ld($data, channel: 'audit')).
  3. Backward Compatibility:
    • Existing Log::debug() calls remain unchanged. ld() is additive.

Compatibility

  • Laravel Versions: Tested on Laravel 9+. For older versions, check spatie/laravel-log-dumper’s support matrix.
  • Monolog Handlers: Works with all Monolog handlers (e.g., stream, syslog, socket). For database logs, ensure the handler supports string serialization.
  • Custom Logging: If using non-Monolog loggers (e.g., monolog/monolog-bridge), verify the LogDumper service binds correctly.

Sequencing

  1. Pre-Release:
    • Audit existing dd()/dump() usage. Replace with ld() in non-critical paths first.
    • Add a linting rule (e.g., PHPStan) to flag ld() calls in production-like environments.
  2. Release:
    • Deploy with APP_DEBUG=false by default. Enable via feature flag for specific users/tenants.
  3. Post-Release:
    • Monitor log volume for anomalies. Set up alerts for unexpected ld() usage in staging/production.
    • Document the ld() pattern in team runbooks (e.g., "How to Debug X").

Operational Impact

Maintenance

  • Low Effort: No moving parts beyond the global function. Updates are composer update + tests.
  • Deprecation Risk: Minimal—MIT license and Spatie’s track record suggest long-term support.
  • Customization:
    • Override the ld() function via a service provider to add metadata (e.g., ld($data, ['user_id' => auth()->id()])).
    • Extend LogDumper to support custom formatters (e.g., JSON, YAML).

Support

  • Debugging Workflow:
    • Pros: Centralized logs reduce context-switching. Easier to grep than scattered dd() outputs.
    • Cons: Requires log aggregation for distributed systems. Team must adopt a naming convention (e.g., [DEBUG] prefix).
  • Error Handling:
    • Logs exceptions silently. Pair with try-catch blocks for critical paths:
      try {
          $result = riskyOperation();
      } catch (\Throwable $e) {
          ld($e, ['context' => 'operation']);
          throw $e;
      }
      
  • Support Matrix:
    Scenario Recommended Action
    Local dev Use freely; no restrictions.
    Staging Enable via feature flag; monitor logs.
    Production Disable unless critical; audit logs.

Scaling

  • Log Volume:
    • Mitigation: Use log levels (e.g., ld($data, level: 'info')) to filter severity.
    • Tooling: Integrate with Laravel Horizon or Telescope to visualize dumps.
  • Performance:
    • Async Logging: For high-frequency dumps, consider spatie/laravel-async-logging to offload I/O.
    • Sampling: Implement a probabilistic sampler (e.g., log only 1% of requests).
  • Distributed Systems:
    • Correlation IDs: Augment dumps with X-Request-ID headers for traceability:
      ld($data, ['request_id' => request()->header('X-Request-ID')]);
      

Failure Modes

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.

Ramp-Up

  • Onboarding:
    • Documentation: Create a team wiki page with:
      • When to use ld() vs. Log::debug().
      • Examples for common use cases (e.g., API payloads, job failures).
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport