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.
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.{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.ConsoleLogger). This hybrid approach is ideal for environments where observability spans multiple contexts.--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.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.APP_DEBUG). Define clear boundaries (e.g., reserve ConsoleLogger for CLI-only contexts) to avoid confusion.ConsoleLogger and Monolog? Will this package replace Monolog entirely, or will it supplement it (e.g., via a custom facade)?phrity/util-* dependencies necessary, or can Laravel’s native tools achieve the same results with less risk?ConsoleLogger fails to initialize (e.g., during a production deployment)?ConsoleLogger, leveraging verbosity flags (e.g., --verbose) for dynamic control.php artisan queue:work, improving visibility into background processes.dd() or var_dump() calls in test suites with structured console logs, enabling better debugging of test failures or edge cases.php artisan migrate, reducing the need to tail log files manually.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}'),
],
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]);
}
ConsoleLogger.Console) to abstract usage and simplify adoption:
facade(Console::class, Phrity\Logger\Console\ConsoleLogger::class);
.env):
LOG_VERBOSITY=verbose
LOG_FORMAT='{datetime} [{level}] {message} - {context}'
ConsoleLogger for all CLI contexts.ConsoleLogger for CLI output.--quiet, -vvv) integrate seamlessly with Artisan’s existing flag system.phrity/util-* packages are compatible with Laravel’s autoloader and do not introduce conflicts with existing dependencies.ConsoleLogger configuration to config/logging.php before integrating it into any commands or scripts.php artisan my:command --verbose).php artisan queue:work --verbose).php artisan test --verbose).Debug) on CLI tool performance, especially in high-frequency contexts like queue workers.phrity/util-* dependencies may complicate future migrations or upgrades, especially if the package is abandoned.--verbose, -vvv).{datetime}, {context}).## 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}'
How can I help you explore Laravel packages today?