diff options
| author | Christian Weiske <cweiske@cweiske.de> | 2012-07-25 18:13:16 +0200 |
|---|---|---|
| committer | Christian Weiske <cweiske@cweiske.de> | 2012-07-25 18:13:16 +0200 |
| commit | 1745804d9bb19325e5c76b054680bd3408176dfe (patch) | |
| tree | 8bcb8ff16e4a730cba9f264ce0b3e67813d4dccd /src/callnotifier/Logger/Debug.php | |
| parent | 2f5e73812960809639489c6ea130237a9e0d290d (diff) | |
| download | auerswald-callnotifier-1745804d9bb19325e5c76b054680bd3408176dfe.tar.gz auerswald-callnotifier-1745804d9bb19325e5c76b054680bd3408176dfe.zip | |
rename echo logger to debug
Diffstat (limited to 'src/callnotifier/Logger/Debug.php')
| -rw-r--r-- | src/callnotifier/Logger/Debug.php | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/src/callnotifier/Logger/Debug.php b/src/callnotifier/Logger/Debug.php new file mode 100644 index 0000000..460f91f --- /dev/null +++ b/src/callnotifier/Logger/Debug.php @@ -0,0 +1,104 @@ +<?php +namespace callnotifier; + +class Logger_Debug implements Logger +{ + public $edss1MsgOnly = false; + + public function __construct() + { + $cc = new \Console_Color2(); + $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'); + $this->purple = $cc->convert('%p'); + } + + public function log($type, $arData) + { + if ($type == 'msgData') { + $this->echoMsgData($arData); + } else if ($type == 'edss1msg') { + $this->echoEDSS1($arData['msg']); + } else { + //other data + echo $this->blue . $type . $this->end . ': ' + . var_export($arData, true) . "\n"; + } + } + + + protected function echoMsgData($arData) + { + if ($this->edss1MsgOnly + && substr($arData['details'], 16, 4) != ' 08 ' + ) { + //only E-DSS-1, no other packets + return; + } + + echo $this->begin . $arData['type'] . $this->end + . ': ' . $arData['details'] . "\n"; + + //Show bytes of N01|N02|T01|T02 etc + 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"; + } + } + + protected function echoEDSS1($msg) + { + echo sprintf( + $this->purple . 'EDSS1_Message' . $this->end + . ' type %02X ' + . $this->purple . '%s' . $this->end + . ' SAPI %d, CR %d, TEI %d, call %d-%s' + . ', %d parameters', + $msg->type, + $msg->getTypeName(), + $msg->sapi, + $msg->callResponse, + $msg->tei, + $msg->callRef, + $msg->callRefType == 0 ? 'source' : 'target', + count($msg->parameters) + ) . "\n"; + + foreach ($msg->parameters as $param) { + echo sprintf( + " Parameter type %02X%s, %d bytes: %s\n", + $param->type, + $param->title + ? ' ' . $this->purple . $param->title . $this->end + : '', + $param->length, + preg_replace('/[^[:print:]]/', '?', $param->data) + . (isset($param->number) + ? ' ' . $this->red . $param->number . $this->end + : '' + ) + ); + if ($param instanceof EDSS1_Parameter_INumber) { + echo sprintf( + " Number type: %s, plan: %s\n", + EDSS1_Parameter_Names::$numberTypes[$param->numberType], + EDSS1_Parameter_Names::$numberingPlans[$param->numberingPlan] + ); + } + } + } +} + +?> |
