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

Log Laravel Package

consolidation/log

A lightweight Laravel logging package that consolidates and formats application logs, helping you centralize output, reduce noise, and improve readability. Designed for easy integration and configuration across environments for consistent, structured logging.

View on GitHub
Deep Wiki
Context7

Getting Started

Install via Composer: composer require consolidation/log. This package provides a StyledLogger that decorates any PSR-3 logger (e.g., Monolog) with CLI-friendly formatting. Start by instantiating a PSR-3 logger (e.g., Monolog\Logger) and wrapping it:

use Consolidation\Log\StyledLogger;
use Monolog\Logger;
use Monolog\Handler\StreamHandler;

$psr3Logger = new Logger('app', [new StreamHandler('php://stdout', Logger::INFO)]);
$logger = StyledLogger::create($psr3Logger);
$logger->info('Task started');

Use it in Symfony Console commands by injecting $logger and calling standard PSR-3 methods (info(), error(), etc.). Output appears styled (colors, indentation, timestamps) without manual formatting.

Implementation Patterns

  • Wrap and delegate: Wrap Monolog or other PSR-3 loggers to inherit robust backends while gaining styled CLI output—no need to replace existing handlers.
  • Symfony Console integration: Pass the StyledLogger to commands via DI; use $logger->debug(), $logger->warning(), etc., and it automatically adapts to verbosity (-v, -vv) and decoration settings.
  • Context-enhanced messages: Embed structured data in context arrays:
    $logger->info('Processing batch', ['batch_size' => 100, 'user_id' => 42]);
    
    Output will include this metadata in a human-readable format (e.g., Processing batch [batch_size=100, user_id=42]).
  • Color control: Check console capabilities before logging:
    if ($output->isDecorated()) {
        $logger->setIsColorized(true);
    }
    
    Avoids garbled output in pipelines or non-TTY environments.

Gotchas and Tips

  • No PSR-3 impl shipped: This package only styles logs—it doesn’t provide a logger backend. Ensure monolog/monolog or similar is installed.
  • NO_COLOR environment variable: Colors are disabled when NO_COLOR=1 is set (per spec). Test locally and in CI with this variable to avoid inconsistent output.
  • Symfony Console verbosity mismatch: StyledLogger respects PSR-3 levels but doesn’t auto-map verbosity flags (e.g., -vvv). Explicitly bump log level in your command:
    $level = $this->input->getOption('verbose') ? Logger::DEBUG : Logger::INFO;
    $psr3Logger->setLevel($level);
    
  • Output decoration quirks: In Windows (especially older PHP versions), colors may not render. Use symfony/console’s OutputInterface::isDecorated() to guard styling logic.
  • Extensibility via subclassing: Override formatMessage() in a custom logger subclass to prepend module prefixes (e.g., [API]) or inject ANSI codes for custom highlighting.
  • Avoid over-decoration: Don’t log massive context objects (e.g., full Doctrine entities)—truncate or select keys to keep CLI output clean and scannable.
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
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
twbs/bootstrap4
php-http/client-implementation
phpcr/phpcr-implementation
cucumber/gherkin-monorepo
haydenpierce/class-finder
psr/simple-cache-implementation
uri-template/tests