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.
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.
StyledLogger to commands via DI; use $logger->debug(), $logger->warning(), etc., and it automatically adapts to verbosity (-v, -vv) and decoration settings.$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]).if ($output->isDecorated()) {
$logger->setIsColorized(true);
}
Avoids garbled output in pipelines or non-TTY environments.monolog/monolog or similar is installed.NO_COLOR=1 is set (per spec). Test locally and in CI with this variable to avoid inconsistent output.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);
symfony/console’s OutputInterface::isDecorated() to guard styling logic.formatMessage() in a custom logger subclass to prepend module prefixes (e.g., [API]) or inject ANSI codes for custom highlighting.How can I help you explore Laravel packages today?