PHP code example of niels-nijens / enhances-console-logging

1. Go to this page and download the library: Download niels-nijens/enhances-console-logging library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

niels-nijens / enhances-console-logging example snippets




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)
    ]
);