c716db893cfcc1814f169b77cc5c168710ce162d
[auerswald-callnotifier.git] / src / callnotifier / Logger / Echo.php
1 <?php
2 namespace callnotifier;
3
4 class Logger_Echo implements Logger
5 {
6     public function __construct()
7     {
8         $cc = new \Console_Color2();
9         $this->begin = $cc->convert('%y');
10         $this->end = $cc->convert('%n');
11         $this->blue = $cc->convert('%b');
12         $this->red = $cc->convert('%r');
13         $this->white = $cc->convert('%w');
14     }
15
16     public function log($type, $arData)
17     {
18         if ($type == 'msgData') {
19             echo $this->begin . $arData['type'] . $this->end
20                 . ': ' . $arData['details'] . "\n";
21             if (preg_match('#^[A-Z][0-9]{2}: (.+)$#', $arData['details'], $matches)) {
22                 $bytestring = $matches[1];
23                 $line = '';
24                 foreach (explode(' ', $bytestring) as $strbyte) {
25                     $line .= chr(hexdec($strbyte));
26                 }
27                 $line = preg_replace(
28                     '/[^[:print:]]/',
29                     $this->white . '?' . $this->end,
30                     $line
31                 );
32                 echo $this->red . '     bytes' . $this->end . ': ' . $line . "\n";
33             }
34         } else {
35             echo $this->blue . $type . $this->end . ': '
36                 . var_export($arData, true) . "\n";
37         }
38     }
39
40 }
41
42 ?>