Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| LogLevelOutputFormatter | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | /** |
| 6 | * Fast Forward Development Tools for PHP projects. |
| 7 | * |
| 8 | * This file is part of fast-forward/dev-tools project. |
| 9 | * |
| 10 | * @author Felipe Sayão Lobato Abreu <github@mentordosnerds.com> |
| 11 | * @license https://opensource.org/licenses/MIT MIT License |
| 12 | * |
| 13 | * @see https://github.com/php-fast-forward/ |
| 14 | * @see https://github.com/php-fast-forward/dev-tools |
| 15 | * @see https://github.com/php-fast-forward/dev-tools/issues |
| 16 | * @see https://php-fast-forward.github.io/dev-tools/ |
| 17 | * @see https://datatracker.ietf.org/doc/html/rfc2119 |
| 18 | */ |
| 19 | |
| 20 | namespace FastForward\DevTools\Console\Formatter; |
| 21 | |
| 22 | use Symfony\Component\Console\Formatter\OutputFormatter; |
| 23 | use Symfony\Component\Console\Formatter\OutputFormatterStyle; |
| 24 | |
| 25 | /** |
| 26 | * Defines additional console styles for log level tags. |
| 27 | * |
| 28 | * This formatter extends the default Symfony output formatter and SHALL |
| 29 | * register a predefined set of styles mapped to common PSR-3 log levels. |
| 30 | * These styles MAY be used by console messages that wrap content in tags |
| 31 | * such as "<error>", "<info>", or "<debug>". |
| 32 | * |
| 33 | * The formatter MUST enable decorated output so that registered styles can |
| 34 | * be rendered by compatible console outputs. Consumers SHOULD use this |
| 35 | * formatter when log messages are emitted with tag names that correspond to |
| 36 | * log levels. |
| 37 | */ |
| 38 | class LogLevelOutputFormatter extends OutputFormatter |
| 39 | { |
| 40 | /** |
| 41 | * Initializes the formatter with predefined styles for log levels. |
| 42 | * |
| 43 | * The registered styles SHALL provide visual differentiation for the |
| 44 | * supported log levels. Implementations MAY extend this formatter if |
| 45 | * additional custom styles are required, but this constructor MUST |
| 46 | * preserve the base formatter behavior by delegating initialization to |
| 47 | * the parent constructor. |
| 48 | */ |
| 49 | public function __construct() |
| 50 | { |
| 51 | $additionalStyles = [ |
| 52 | 'emergency' => new OutputFormatterStyle('red', null, ['bold']), |
| 53 | 'alert' => new OutputFormatterStyle('red', null, ['bold']), |
| 54 | 'critical' => new OutputFormatterStyle('red', null, ['bold']), |
| 55 | 'error' => new OutputFormatterStyle('red'), |
| 56 | 'warning' => new OutputFormatterStyle('yellow'), |
| 57 | 'notice' => new OutputFormatterStyle('blue'), |
| 58 | 'info' => new OutputFormatterStyle('green'), |
| 59 | 'debug' => new OutputFormatterStyle('cyan'), |
| 60 | ]; |
| 61 | |
| 62 | parent::__construct(true, $additionalStyles); |
| 63 | } |
| 64 | } |