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

Logger Console Laravel Package

phrity/logger-console

PSR-3 compatible console logger for local tests and CLI apps. Configure verbosity levels (quiet to debug), customize output format with placeholders (datetime, level, message, context), and optionally read verbosity from CLI flags like -q/-v/-vv/-vvv.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • PSR-3 Compliance: The package’s adherence to PSR-3 ensures seamless integration with Laravel’s Monolog-based logging system, allowing it to act as a drop-in or supplementary logger for console-specific needs. This compatibility reduces architectural friction and leverages existing logging infrastructure.
  • Verbosity Granularity: The five-tier verbosity system (Quiet to Debug) aligns with Laravel’s CLI-driven workflows (e.g., Artisan commands, tests) and provides a scalable way to control log output without modifying application logic. This is particularly valuable for debugging complex CLI scripts or test suites.
  • Format Customization: The ability to define output formats via string templates (e.g., {datetime} {level} {message}) enables standardization across CLI tools, improving readability and reducing cognitive load for developers. This is especially useful in collaborative environments where consistency is key.
  • Symfony Console Integration: The dependency on Symfony’s Console component is a strength, as Laravel’s Artisan already uses this component. This ensures compatibility with Laravel’s CLI ecosystem and minimizes integration overhead.

Integration Feasibility

  • Laravel Ecosystem: The package can coexist with Monolog, allowing teams to route logs to both file/database systems (via Monolog) and console (via ConsoleLogger). This hybrid approach is ideal for environments where observability spans multiple contexts.
  • Artisan Command Enhancement: The CLI options (--quiet, -vvv) can be exposed directly in Artisan commands, enabling developers to control log verbosity without code changes. This lowers the barrier to adoption and improves developer experience.
  • Test and Dev Environments: The package is well-suited for local development, testing, and debugging scenarios where console logs are preferred over traditional log files. Its lightweight nature makes it ideal for these use cases without adding significant overhead.

Technical Risk

  • Dependency Risks:
    • The package introduces phrity/util-* dependencies, which are not widely used in the Laravel ecosystem. Assess whether these dependencies are critical or if Laravel’s built-in tools (e.g., sprintf for string interpolation) can achieve the same functionality. Over-reliance on niche dependencies may complicate future maintenance.
    • PHP Version Constraint: The requirement for PHP 8.1+ may pose challenges for teams still using Laravel 8.x or older versions. However, Laravel 9+ (PHP 8.1+) is the target for most modern applications, reducing this risk for new projects.
  • Stability and Adoption:
    • The package’s lack of stars or dependents indicates limited adoption, which could signal unproven stability. Conduct thorough testing in a staging environment to validate reliability before full integration.
    • Verbosity Conflict: There is a risk of overlap between this package’s verbosity system and Laravel’s existing debug modes (e.g., APP_DEBUG). Define clear boundaries (e.g., reserve ConsoleLogger for CLI-only contexts) to avoid confusion.
  • Key Questions:
    • How will logs be routed between ConsoleLogger and Monolog? Will this package replace Monolog entirely, or will it supplement it (e.g., via a custom facade)?
    • Are the phrity/util-* dependencies necessary, or can Laravel’s native tools achieve the same results with less risk?
    • What fallback mechanism exists if ConsoleLogger fails to initialize (e.g., during a production deployment)?

Integration Approach

Stack Fit

  • Primary Use Cases:
    • Artisan Commands: Replace or supplement Monolog’s logging in Artisan commands with ConsoleLogger, leveraging verbosity flags (e.g., --verbose) for dynamic control.
    • Queue Workers: Log job progress or errors directly to the console during php artisan queue:work, improving visibility into background processes.
    • Testing: Replace dd() or var_dump() calls in test suites with structured console logs, enabling better debugging of test failures or edge cases.
    • Migrations: Log schema changes or migration steps to the console during php artisan migrate, reducing the need to tail log files manually.
  • Secondary Use Cases:
    • API Debugging: Temporarily route API logs to the console during local development or testing to simplify debugging.
    • Cron Jobs: Log execution details of cron jobs to the console when run via CLI, aiding in monitoring and troubleshooting.

Migration Path

  1. Phase 1: Pilot Integration
    • Register ConsoleLogger as a secondary logger in Laravel’s configuration (config/logging.php):
      'console' => [
          'driver' => 'custom',
          'via' => Phrity\Logger\Console\ConsoleLogger::class,
          'verbosity' => env('LOG_VERBOSITY', 'normal'),
          'format' => env('LOG_FORMAT', '{datetime} [{level}] {message}'),
      ],
      
    • Integrate the logger into a single Artisan command to validate functionality:
      use Phrity\Logger\Console\ConsoleLogger;
      protected $logger;
      public function __construct() {
          $this->logger = new ConsoleLogger(cliOptions: true);
      }
      public function handle() {
          $this->logger->info('Command started', ['user_id' => 1]);
      }
      
  2. Phase 2: Standardization
    • Replace Monolog-based logging in CLI-specific files (e.g., commands, jobs, tests) with ConsoleLogger.
    • Create a helper facade (e.g., Console) to abstract usage and simplify adoption:
      facade(Console::class, Phrity\Logger\Console\ConsoleLogger::class);
      
    • Configure default verbosity and format via environment variables (.env):
      LOG_VERBOSITY=verbose
      LOG_FORMAT='{datetime} [{level}] {message} - {context}'
      
  3. Phase 3: Full Adoption
    • Replace Monolog’s console handler entirely with ConsoleLogger for all CLI contexts.
    • Deprecate custom log formatting in favor of the package’s templating system.
    • Document the new logging standards in the team’s internal guidelines.

Compatibility

  • Laravel Versions: The package is compatible with Laravel 9+ (PHP 8.1+). For Laravel 8.x or older, assess whether the PHP version constraint is a blocker or if a custom fork is feasible.
  • Monolog Coexistence: The package can coexist with Monolog by routing logs to both systems. For example, use Monolog for file/database logging and ConsoleLogger for CLI output.
  • Symfony Console: No compatibility issues are expected, as Laravel’s Artisan already uses this component. The package’s CLI options (--quiet, -vvv) integrate seamlessly with Artisan’s existing flag system.

Sequencing

  1. Dependency Validation: Ensure phrity/util-* packages are compatible with Laravel’s autoloader and do not introduce conflicts with existing dependencies.
  2. Configuration Setup: Add the ConsoleLogger configuration to config/logging.php before integrating it into any commands or scripts.
  3. Testing: Validate the logger’s output in the following contexts:
    • Artisan commands (php artisan my:command --verbose).
    • Queue workers (php artisan queue:work --verbose).
    • Test suites (php artisan test --verbose).
    • Custom scripts or cron jobs.
  4. Performance Benchmarking: Measure the impact of high-verbosity modes (e.g., Debug) on CLI tool performance, especially in high-frequency contexts like queue workers.

Operational Impact

Maintenance

  • Pros:
    • Reduced Boilerplate: Centralizes log formatting and verbosity control, reducing the need for custom logging logic across CLI tools.
    • Consistent Output: Standardizes log formats across Artisan commands, queues, and tests, improving readability and maintainability.
    • Low Maintenance Overhead: The MIT license and minimal dependencies suggest low ongoing maintenance effort, provided the package remains stable.
  • Cons:
    • Vendor Lock-in: Custom phrity/util-* dependencies may complicate future migrations or upgrades, especially if the package is abandoned.
    • Debugging Complexity: Misconfigured log formats or verbosity settings could lead to unreadable or misleading console output, requiring additional debugging effort.

Support

  • Proactive Measures:
    • Document the new logging system in the team’s internal developer portal, including:
      • Available verbosity levels and their CLI flags (e.g., --verbose, -vvv).
      • Custom format templates and their placeholders (e.g., {datetime}, {context}).
      • Examples of usage in Artisan commands, tests, and scripts.
    • Provide a quick-reference guide for new developers:
      ## CLI Logging Guide
      Control log verbosity with flags:
      ```bash
      php artisan my:command --verbose   # Verbose logs
      php artisan my:command -vvv        # Debug logs
      php artisan my:command --quiet     # Minimal logs
      
      Customize log format in .env:
      LOG_FORMAT='{datetime} [{level}] {message} - {context}'
      
  • Troubleshooting:
    • Monitor the package’s GitHub repository for updates or issues, though low activity may require internal fixes.
    • Implement a fallback mechanism (e.g., revert to Mon
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.
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor