1 | <?php |
||
9 | class OutputInterfaceAdapter implements LoggerInterface |
||
10 | { |
||
11 | use \Psr\Log\LoggerTrait; |
||
12 | |||
13 | private |
||
14 | $output, |
||
|
|||
15 | $levelConversionTable; |
||
16 | |||
17 | public function __construct(OutputInterface $output) |
||
18 | { |
||
19 | $this->output = $output; |
||
20 | |||
21 | $this->levelConversionTable = array( |
||
22 | LogLevel::DEBUG => OutputInterface::VERBOSITY_VERBOSE, |
||
23 | LogLevel::INFO => OutputInterface::VERBOSITY_NORMAL, |
||
24 | LogLevel::WARNING => OutputInterface::VERBOSITY_NORMAL, |
||
25 | LogLevel::ERROR => OutputInterface::VERBOSITY_NORMAL |
||
26 | ); |
||
27 | } |
||
28 | |||
29 | public function log($level, $message, array $context = array()) |
||
30 | { |
||
31 | if($this->convertLevel($level) <= $this->output->getVerbosity()) |
||
32 | { |
||
33 | $this->writeLevel($level); |
||
34 | $this->output->writeln($message, OutputInterface::OUTPUT_NORMAL); |
||
35 | } |
||
36 | } |
||
37 | |||
38 | private function convertLevel($level) |
||
39 | { |
||
40 | $verbosity = OutputInterface::VERBOSITY_NORMAL; |
||
41 | |||
42 | if(array_key_exists($level, $this->levelConversionTable)) |
||
43 | { |
||
44 | $verbosity = $this->levelConversionTable[$level]; |
||
45 | } |
||
46 | |||
47 | return $verbosity; |
||
48 | } |
||
49 | |||
50 | private function writeLevel($level) |
||
59 | |||
60 | private function colorizeMessage($level, $message) |
||
61 | { |
||
62 | $colors = array( |
||
78 | } |
Only declaring a single property per statement allows you to later on add doc comments more easily.
It is also recommended by PSR2, so it is a common style that many people expect.