decode debug bytes and display them in echo logger
authorChristian Weiske <cweiske@cweiske.de>
Sun, 15 Jul 2012 20:48:25 +0000 (22:48 +0200)
committerChristian Weiske <cweiske@cweiske.de>
Sun, 15 Jul 2012 20:48:25 +0000 (22:48 +0200)
src/callnotifier/Logger/Echo.php

index eec9bb15dae3d14c11df7966ef8702469b114a48..c716db893cfcc1814f169b77cc5c168710ce162d 100644 (file)
@@ -9,6 +9,8 @@ class Logger_Echo implements Logger
         $this->begin = $cc->convert('%y');
         $this->end = $cc->convert('%n');
         $this->blue = $cc->convert('%b');
+        $this->red = $cc->convert('%r');
+        $this->white = $cc->convert('%w');
     }
 
     public function log($type, $arData)
@@ -16,6 +18,19 @@ class Logger_Echo implements Logger
         if ($type == 'msgData') {
             echo $this->begin . $arData['type'] . $this->end
                 . ': ' . $arData['details'] . "\n";
+            if (preg_match('#^[A-Z][0-9]{2}: (.+)$#', $arData['details'], $matches)) {
+                $bytestring = $matches[1];
+                $line = '';
+                foreach (explode(' ', $bytestring) as $strbyte) {
+                    $line .= chr(hexdec($strbyte));
+                }
+                $line = preg_replace(
+                    '/[^[:print:]]/',
+                    $this->white . '?' . $this->end,
+                    $line
+                );
+                echo $this->red . '     bytes' . $this->end . ': ' . $line . "\n";
+            }
         } else {
             echo $this->blue . $type . $this->end . ': '
                 . var_export($arData, true) . "\n";