niels-nijens / enhances-console-logging
Components to enhance Symfony console & stdout logging.
Installs: 2 063
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: ^7.2
- psr/log: ^1.1
- symfony/console: ^4.4 || ^5.1
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.16
- symfony/phpunit-bridge: ^5.1
This package is auto-updated.
Last update: 2024-11-05 16:02:45 UTC
README
Components to enhance Symfony console & stdout logging.
Installation using Composer
Run the following command to add the package to the composer.json of your project:
composer require niels-nijens/enhances-console-logging
Usage
ProgressBarConsoleLogger
The ProgressBarConsoleLogger
allows you to log and show progress in a console without directly injecting a
ProgressBar
into your domain components handling the progression. Instead, you are able to inject logging into those
components. This allows you to not only log to the console/stdout, but also to other logging mechanisms (eg. a file).
Logging to both a progress bar and another logging mechanism can be achieved by injecting/decorating an existing PSR-3 logger, like Monolog.
The ProgressBarConsoleLogger
adheres to the PSR-3 logging specification and as such implements the Psr\Log\LoggerInterface
.
<?php declare(strict_types=1); use Nijens\EnhancesConsoleLogging\ProgressBar\LogContext; use Nijens\EnhancesConsoleLogging\ProgressBar\ProgressBarConsoleLogger; use Psr\Log\LoggerInterface; use Symfony\Component\Console\Helper\ProgressBar; use Symfony\Component\Console\Output\OutputInterface; /** @var $monolog LoggerInterface */ /** @var $output OutputInterface */ $progressBar = new ProgressBar($output); $logger = new ProgressBarConsoleLogger($monolog); $logger->registerProgressBar( 'test', // A unique identifier to reference the progress bar through the log context. $progressBar ); $logger->info( 'This message will be set on the progress bar.', [ LogContext::PROGRESS_IDENTIFIER_KEY => 'test', // The unique identifier. LogContext::PROGRESS_INCREMENT_KEY => 0, // Allows incrementing the max steps. (optional) LogContext::PROGRESS_ADVANCE_KEY => 0, // Allows advancing the steps. (optional) ] );
Testing and code standards
Unit tests can be executed by running the following command:
composer test
Code style can be fixed or validated by running one of the following commands:
composer cs-fixer || composer cs-validate
Security
If you discover any security related issues, please email nijens.niels+security [at] gmail.com instead of using the issue tracker.
Credits
License
This package is licensed under the MIT License. Please see the LICENSE file for more information.