PHP code example of imponeer / log-data-output-decorator

1. Go to this page and download the library: Download imponeer/log-data-output-decorator 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/ */

    

imponeer / log-data-output-decorator example snippets


use Imponeer\Decorators\LogDataOutput\OutputDecorator;
use Symfony\Component\Console\Output\ConsoleOutput;

$output = new OutputDecorator(new ConsoleOutput());

// Different message types
$output->info('This is an info message');
$output->success('Operation completed successfully');
$output->error('An error occurred');
$output->fatal('Critical error - application stopping');
$output->msg('Plain message without formatting');

$output->info('Main process started');
$output->incrIndent();
$output->info('Sub-process 1');
$output->info('Sub-process 2');
$output->incrIndent();
$output->info('Nested sub-process');
$output->decrIndent();
$output->info('Back to sub-process level');
$output->resetIndent();
$output->info('Back to main level');

$output->info('Processing file: %s', 'example.txt');
$output->success('Processed %d files in %s seconds', 42, '1.23');
$output->error('Failed to process %s: %s', 'file.txt', 'Permission denied');

use Imponeer\Decorators\LogDataOutput\OutputDecorator;
use Symfony\Component\Console\Output\BufferedOutput;

$bufferedOutput = new BufferedOutput();
$output = new OutputDecorator($bufferedOutput);

$output->info('Starting batch process');
$output->incrIndent();

foreach (['file1.txt', 'file2.txt', 'file3.txt'] as $index => $file) {
    $output->info('Processing file %d: %s', $index + 1, $file);
    $output->incrIndent();

    if ($file === 'file2.txt') {
        $output->error('Failed to process %s', $file);
    } else {
        $output->success('Successfully processed %s', $file);
    }

    $output->decrIndent();
}

$output->resetIndent();
$output->info('Batch process completed');

// Get the formatted output
echo $bufferedOutput->fetch();