Weave 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

Loggable Command Bundle Laravel Package

bizkit/loggable-command-bundle

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • CQRS/Event-Driven Fit: Ideal for Laravel applications leveraging Laravel Echo, Laravel Horizon, or Laravel Queues (e.g., bus/message handlers). Aligns with Symfony’s messaging patterns but requires abstraction for Laravel’s Illuminate\Bus or Illuminate\Queue systems.
  • Command/Job Isolation: Perfect for long-running jobs (e.g., batch processing, API integrations) where granular logging per execution is critical.
  • Monolog Integration: Leverages Laravel’s native Monolog support (via monolog/monolog), reducing friction in adoption.

Integration Feasibility

  • Symfony vs. Laravel: Requires Symfony Bridge (symfony/messenger, symfony/console) or custom Laravel command/message handler wrappers to bridge Symfony’s CommandBus/MessageBus with Laravel’s Bus/Queue.
  • Monolog Configuration: Laravel’s config/logging.php must be extended to support dynamic channel creation per command/job. Potential conflicts with Laravel’s default log channels (e.g., single, daily).
  • Attribute/Annotation Support: Laravel’s PHP 8 attributes (native) or Doctrine annotations (via doctrine/annotations) can replace Symfony’s annotations with minimal refactoring.

Technical Risk

  • Laravel-Specific Gaps:
    • No native support for Laravel’s Artisan commands or Queued Jobs (requires middleware/adapters).
    • Risk of log file proliferation if not constrained (e.g., per-job vs. per-command).
  • Performance Overhead:
    • Dynamic file handler creation per command/job may introduce I/O latency in high-throughput systems.
    • Memory leaks if handlers aren’t properly closed (Symfony’s CommandBus handles this; Laravel’s Bus may not).
  • Dependency Bloat:
    • Pulls in Symfony components (symfony/console, symfony/messenger), increasing bundle size (~1–2MB).

Key Questions

  1. Use Case Clarity:
    • Are logs needed for all commands/jobs, or only specific ones (e.g., critical paths)?
    • Will this replace existing logging (e.g., Laravel’s Log::channel()) or supplement it?
  2. Log Management:
    • How will log files be rotated/archived? (Bundle supports rotating handlers but requires config.)
    • Will log aggregation (e.g., ELK, Loki) be used, or is file-based logging sufficient?
  3. Laravel-Specific Workarounds:
    • How will Artisan commands and Queued Jobs be mapped to Symfony’s Command/Message interfaces?
    • Will a custom LoggableCommandBus or Queue listener be needed?
  4. Testing & Debugging:
    • How will logs be correlated with Laravel’s existing debug tools (e.g., telescope, laravel-debugbar)?
    • What’s the fallback if the bundle fails (e.g., silent failure vs. graceful degradation)?

Integration Approach

Stack Fit

  • Core Stack: Laravel 8+/9+ with Monolog (native) and Symfony Messenger Bridge (if using symfony/messenger).
  • Alternatives:
    • For Artisan commands: Use Laravel’s Command class + custom trait to inject logging.
    • For Queued Jobs: Extend ShouldQueue with a Loggable interface/trait.
  • Dependencies:
    • bizkit/loggable-command-bundle (primary)
    • symfony/messenger (if using message handlers)
    • symfony/console (for command support)
    • doctrine/annotations (if using annotations; optional for PHP 8 attributes).

Migration Path

  1. Phase 1: Proof of Concept
    • Implement for one critical command/job (e.g., SendEmailJob).
    • Test log file creation, rotation, and output (stdout/stderr).
  2. Phase 2: Laravel Integration Layer
    • Create a LoggableCommand trait for Artisan commands:
      use Bizkit\LoggableCommandBundle\Attribute\Loggable;
      #[Loggable] class MyCommand extends Command { ... }
      
    • For Queued Jobs, use a listener to wrap job execution:
      $job->handle(); // Wrapped to log to dedicated file
      
  3. Phase 3: Full Adoption
    • Replace Log::channel() calls in commands/jobs with bundle attributes.
    • Configure Monolog to exclude default channels from loggable commands (via exclusive_channels in bundle config).

Compatibility

  • Laravel-Specific:
    • Artisan: Works with symfony/console integration (minimal changes).
    • Queues: Requires custom job middleware or queue listener to inject logging.
    • Events: Not natively supported; may need EventDispatcher integration.
  • Monolog:
    • Conflicts possible with Laravel’s default log channels (e.g., single). Solution: Use exclusive_channels to isolate loggable commands.
  • PHP Attributes:
    • Prefer PHP 8 attributes over annotations for Laravel compatibility.

Sequencing

  1. Setup:
    • Install bundle via Composer.
    • Configure config/packages/bizkit_loggable_command.yaml (or Laravel service provider).
  2. Command Integration:
    • Add #[Loggable] to Artisan commands.
    • Test log output in php artisan CLI.
  3. Queue Integration:
    • Create a LoggableJob trait/middleware.
    • Apply to critical jobs (e.g., SendPaymentJob).
  4. Monitoring:
    • Validate log file creation/rotation.
    • Check for performance impact in load tests.

Operational Impact

Maintenance

  • Pros:
    • Isolated logs reduce noise in main application logs.
    • Per-command config via attributes/annotations enables fine-grained control.
  • Cons:
    • Additional config for Monolog (e.g., exclusive_channels, handlers).
    • Dependency on Symfony components may complicate future Laravel updates.
  • Mitigations:
    • Document Monolog setup in README.
    • Use Laravel’s config/logging.php to override default channels for loggable commands.

Support

  • Debugging:
    • Logs are command/job-specific, aiding in root-cause analysis.
    • No native Laravel integration means support may require custom troubleshooting (e.g., checking file permissions, Monolog config).
  • Tooling:
    • Works with Laravel Telescope if logs are streamed to a central channel.
    • Tailwind CSS or tail -f for CLI log inspection.
  • Community:
    • Low adoption (0 stars, 0 dependents) may limit community support. Plan for internal maintenance.

Scaling

  • Performance:
    • File I/O overhead: Each command/job creates a new log file. Mitigate with:
      • Log rotation (configured in bundle).
      • Asynchronous logging (e.g., symfony/messenger transport for logs).
    • Memory: Handlers must be closed post-execution (Symfony handles this; Laravel may need cleanup).
  • Infrastructure:
    • Log volume: Expect N log files for N command/job executions. Plan for:
      • Storage quotas (e.g., S3, local disk).
      • Retention policies (e.g., 7-day rotation).
    • Distributed systems: Logs may be node-local; consider aggregating via syslog or Fluentd.

Failure Modes

Failure Scenario Impact Mitigation
Monolog misconfiguration No logs generated Validate exclusive_channels and handler setup.
File permission issues Logs written to wrong location Use storage/logs/ with 0777 permissions.
Symfony component conflicts Bundle fails to load Isolate in a separate service provider.
High command/job volume Disk I/O saturation Limit loggable commands to critical paths.
Laravel update breaks compatibility Bundle stops working Pin Symfony dependencies or fork the bundle.

Ramp-Up

  • Developer Onboarding:
    • 1–2 hours to understand Monolog + bundle config.
    • 30 mins to add #[Loggable] to a command/job.
  • CI/CD:
    • Add tests for log file creation (e.g., assertFileExists(storage/logs/CommandName.log)).
    • Validate log rotation in staging.
  • Training:
    • Document when to use (e.g., "
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.
adachsoft/changelog-linter
adachsoft/collection
payerurl/telegrambot-crypto-payment-instant-payout
dskripchenko/laravel-hybrid-search
riorizkyrainey/lara-ced
mehedimi/static-vel
zharp/zharp
nonsapiens/bigquery-model-sync
lgu-bayambang-ict-office/lgu-laravel-development-standards
andydefer/laravel-support
se7enxweb/flysystem
lampwick/laravel
jeslage/statamic-emojis
micahdshackelford/rmap-laravel
draftsmaninc/draftsman
square-bit/laravel-volition
himito/laravel-mailman
htinlynn/genius-helper
maco-studios/hephaestus
adachsoft/php-code-style