1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Karma\Logging; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
6
|
|
|
|
7
|
|
|
trait OutputAware |
8
|
|
|
{ |
9
|
|
|
protected |
10
|
|
|
$output = null; |
11
|
|
|
|
12
|
|
|
public function setOutput(OutputInterface $output) |
13
|
|
|
{ |
14
|
|
|
$this->output = $output; |
15
|
|
|
|
16
|
|
|
return $this; |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
protected function error($messages, $newline = false, $type = OutputInterface::OUTPUT_NORMAL) |
20
|
|
|
{ |
21
|
|
|
return $this->write($messages, $newline, $type, OutputInterface::VERBOSITY_NORMAL, 'red'); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
protected function warning($messages, $newline = false, $type = OutputInterface::OUTPUT_NORMAL) |
25
|
|
|
{ |
26
|
|
|
return $this->write($messages, $newline, $type, OutputInterface::VERBOSITY_NORMAL, 'yellow'); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
protected function info($messages, $newline = false, $type = OutputInterface::OUTPUT_NORMAL) |
30
|
|
|
{ |
31
|
|
|
return $this->write($messages, $newline, $type, OutputInterface::VERBOSITY_NORMAL, 'white'); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
protected function debug($messages, $newline = false, $type = OutputInterface::OUTPUT_NORMAL) |
35
|
|
|
{ |
36
|
|
|
return $this->write($messages, $newline, $type, OutputInterface::VERBOSITY_VERBOSE, 'white'); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
private function write($messages, $newline, $type, $verbosity, $textColor) |
40
|
|
|
{ |
41
|
|
|
if($this->output instanceof OutputInterface) |
42
|
|
|
{ |
43
|
|
|
if($verbosity <= $this->output->getVerbosity()) |
44
|
|
|
{ |
45
|
|
|
if(! is_array($messages)) |
46
|
|
|
{ |
47
|
|
|
$messages = array($messages); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
array_walk($messages, function(& $message) use($textColor) { |
51
|
|
|
$message = "<fg=$textColor>$message</fg=$textColor>"; |
52
|
|
|
}); |
53
|
|
|
|
54
|
|
|
$this->output->write($messages, $newline, $type); |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|