|
1 | | -[](LICENSE) |
2 | | -[](https://github.com/imponeer/log-data-output-decorator/releases) [](https://codeclimate.com/github/imponeer/log-data-output-decorator/maintainability) [](http://php.net) |
3 | | -[](https://packagist.org/packages/imponeer/log-data-output-decorator) |
| 1 | +[](LICENSE) [](https://github.com/imponeer/log-data-output-decorator/releases) [](http://php.net) [](https://packagist.org/packages/imponeer/log-data-output-decorator) |
4 | 2 |
|
5 | | -# Log data output decorator |
| 3 | +# Log Data Output Decorator |
6 | 4 |
|
7 | | -Small decorator that extends [Symfony OutputInterface](https://github.com/symfony/console/blob/5.x/Output/OutputInterface.php) delivered class with few options for easier to log data. |
| 5 | +A decorator that extends [Symfony OutputInterface](https://github.com/symfony/console/blob/7.x/Output/OutputInterface.php) with: |
| 6 | + |
| 7 | +- Multiple message types: info, success, error, fatal, and plain messages |
| 8 | +- Automatic indentation with indent control methods |
| 9 | +- Parameter substitution using sprintf formatting |
| 10 | +- Full Symfony OutputInterface compatibility |
8 | 11 |
|
9 | 12 | ## Installation |
10 | 13 |
|
11 | | -To install and use this package, we recommend to use [Composer](https://getcomposer.org): |
| 14 | +Install via [Composer](https://getcomposer.org): |
12 | 15 |
|
13 | 16 | ```bash |
14 | 17 | composer require imponeer/log-data-output-decorator |
15 | 18 | ``` |
16 | 19 |
|
17 | | -Otherwise, you need to include manually files from `src/` directory. |
| 20 | +## Usage |
| 21 | + |
| 22 | +### Basic Usage |
| 23 | + |
| 24 | +```php |
| 25 | +use Imponeer\Decorators\LogDataOutput\OutputDecorator; |
| 26 | +use Symfony\Component\Console\Output\ConsoleOutput; |
| 27 | + |
| 28 | +$output = new OutputDecorator(new ConsoleOutput()); |
| 29 | + |
| 30 | +// Different message types |
| 31 | +$output->info('This is an info message'); |
| 32 | +$output->success('Operation completed successfully'); |
| 33 | +$output->error('An error occurred'); |
| 34 | +$output->fatal('Critical error - application stopping'); |
| 35 | +$output->msg('Plain message without formatting'); |
| 36 | +``` |
18 | 37 |
|
19 | | -## Usage example |
| 38 | +### Indentation Support |
20 | 39 |
|
21 | 40 | ```php |
22 | | -$output = new \Imponeer\Decorators\LogDataOutput\OutputDecorator( |
23 | | - new \Symfony\Component\Console\Output\BufferedOutput(); |
24 | | -); |
25 | | -$output->info('test'); |
| 41 | +$output->info('Main process started'); |
26 | 42 | $output->incrIndent(); |
27 | | -$output->info('#1'); |
28 | | -$output->info('#2'); |
| 43 | +$output->info('Sub-process 1'); |
| 44 | +$output->info('Sub-process 2'); |
| 45 | +$output->incrIndent(); |
| 46 | +$output->info('Nested sub-process'); |
| 47 | +$output->decrIndent(); |
| 48 | +$output->info('Back to sub-process level'); |
| 49 | +$output->resetIndent(); |
| 50 | +$output->info('Back to main level'); |
| 51 | +``` |
| 52 | + |
| 53 | +Output: |
| 54 | +``` |
| 55 | +Main process started |
| 56 | + Sub-process 1 |
| 57 | + Sub-process 2 |
| 58 | + Nested sub-process |
| 59 | + Back to sub-process level |
| 60 | +Back to main level |
| 61 | +``` |
| 62 | + |
| 63 | +### Parameter Substitution |
| 64 | + |
| 65 | +```php |
| 66 | +$output->info('Processing file: %s', 'example.txt'); |
| 67 | +$output->success('Processed %d files in %s seconds', 42, '1.23'); |
| 68 | +$output->error('Failed to process %s: %s', 'file.txt', 'Permission denied'); |
29 | 69 | ``` |
30 | 70 |
|
31 | | -## How to contribute? |
| 71 | +### Advanced Example |
| 72 | + |
| 73 | +```php |
| 74 | +use Imponeer\Decorators\LogDataOutput\OutputDecorator; |
| 75 | +use Symfony\Component\Console\Output\BufferedOutput; |
| 76 | + |
| 77 | +$bufferedOutput = new BufferedOutput(); |
| 78 | +$output = new OutputDecorator($bufferedOutput); |
| 79 | + |
| 80 | +$output->info('Starting batch process'); |
| 81 | +$output->incrIndent(); |
| 82 | + |
| 83 | +foreach (['file1.txt', 'file2.txt', 'file3.txt'] as $index => $file) { |
| 84 | + $output->info('Processing file %d: %s', $index + 1, $file); |
| 85 | + $output->incrIndent(); |
| 86 | + |
| 87 | + if ($file === 'file2.txt') { |
| 88 | + $output->error('Failed to process %s', $file); |
| 89 | + } else { |
| 90 | + $output->success('Successfully processed %s', $file); |
| 91 | + } |
| 92 | + |
| 93 | + $output->decrIndent(); |
| 94 | +} |
| 95 | + |
| 96 | +$output->resetIndent(); |
| 97 | +$output->info('Batch process completed'); |
| 98 | + |
| 99 | +// Get the formatted output |
| 100 | +echo $bufferedOutput->fetch(); |
| 101 | +``` |
| 102 | + |
| 103 | +## API Documentation |
| 104 | + |
| 105 | +Complete API documentation with all methods and examples is available in the [project wiki](https://github.com/imponeer/log-data-output-decorator/wiki), which is automatically generated from the source code. |
| 106 | + |
| 107 | +## Testing |
| 108 | + |
| 109 | +Run the test suite: |
| 110 | + |
| 111 | +```bash |
| 112 | +composer test |
| 113 | +``` |
| 114 | + |
| 115 | +Check code style compliance: |
| 116 | + |
| 117 | +```bash |
| 118 | +composer phpcs |
| 119 | +``` |
| 120 | + |
| 121 | +Fix code style issues automatically: |
| 122 | + |
| 123 | +```bash |
| 124 | +composer phpcbf |
| 125 | +``` |
| 126 | + |
| 127 | +Run static analysis: |
| 128 | + |
| 129 | +```bash |
| 130 | +composer phpstan |
| 131 | +``` |
| 132 | + |
| 133 | +## Contributing |
| 134 | + |
| 135 | +We welcome contributions! Here's how you can help: |
| 136 | + |
| 137 | +1. **Fork the repository** on GitHub |
| 138 | +2. **Create a feature branch** (`git checkout -b feature/amazing-feature`) |
| 139 | +3. **Make your changes** and add tests if applicable |
| 140 | +4. **Run the test suite** to ensure everything works |
| 141 | +5. **Commit your changes** (`git commit -am 'Add amazing feature'`) |
| 142 | +6. **Push to the branch** (`git push origin feature/amazing-feature`) |
| 143 | +7. **Create a Pull Request** |
| 144 | + |
| 145 | +### Development Guidelines |
| 146 | + |
| 147 | +- Follow PSR-12 coding standards |
| 148 | +- Add tests for new functionality |
| 149 | +- Update documentation for API changes |
| 150 | +- Ensure all tests pass before submitting PR |
| 151 | + |
| 152 | +### Reporting Issues |
32 | 153 |
|
33 | | -If you want to add some functionality or fix bugs, you can fork, change and create pull request. If you not sure how this works, try [interactive GitHub tutorial](https://skills.github.com). |
| 154 | +Found a bug or have a suggestion? Please [open an issue](https://github.com/imponeer/log-data-output-decorator/issues) with: |
34 | 155 |
|
35 | | -If you found any bug or have some questions, use [issues tab](https://github.com/imponeer/log-data-output-decorator/issues) and write there your questions. |
| 156 | +- Clear description of the problem or suggestion |
| 157 | +- Steps to reproduce (for bugs) |
| 158 | +- Expected vs actual behavior |
| 159 | +- PHP and Symfony Console versions |
0 commit comments