Add debug message output to call loggers
authorChristian Weiske <cweiske@cweiske.de>
Wed, 13 Mar 2019 16:01:30 +0000 (17:01 +0100)
committerChristian Weiske <cweiske@cweiske.de>
Wed, 13 Mar 2019 16:01:30 +0000 (17:01 +0100)
src/callnotifier/CLI.php
src/callnotifier/Log.php
src/callnotifier/Logger/CallBase.php
src/callnotifier/Logger/CallDreambox.php

index 0b8ae60773c1cac7a48ca2dfa51776aa4b9bb7b2..564a5f5a1985692b828b6e8b39a4a5dd645d35e6 100644 (file)
@@ -133,7 +133,7 @@ class CLI
      *
      * @return string Full path of config file or NULL if no file found
      */
-    protected function getConfigFile()
+    public function getConfigFile()
     {
         if (basename(dirname(__DIR__)) == 'src'
             && file_exists(__DIR__ . '/../../data/callnotifier.config.php')
@@ -157,4 +157,4 @@ class CLI
     }
 }
 
-?>
\ No newline at end of file
+?>
index d2ee0c83a42e083fd1f764294c43ea2db84c3012..a831066540196d587782fd7e484c625bf3a51da9 100644 (file)
@@ -3,6 +3,8 @@ namespace callnotifier;
 
 class Log
 {
+    public $debug = false;
+
     /**
      * Array of logger object arrays.
      * Key is the notification type, value is an array of logger objects
@@ -33,6 +35,10 @@ class Log
         }
         $types = (array)$types;
 
+        if ($this->debug) {
+            $logger->debug = $this->debug;
+        }
+
         foreach ($types as $type) {
             if (!isset($this->logger[$type])) {
                 throw new \Exception('Unknown log type: ' . $type);
@@ -46,9 +52,12 @@ class Log
         if (!isset($this->logger[$type])) {
             throw new \Exception('Unknown log type: ' . $type);
         }
-        
+
         if (count($this->logger[$type])) {
             foreach ($this->logger[$type] as $logger) {
+                if ($this->debug) {
+                    echo "Logging to " . get_class($logger) . "\n";
+                }
                 $logger->log($type, $arData);
             }
         }
index 31ad0bc7ce8408af85115d75081e0b24939d82f0..2a1d3e8a22bc533c401be8143201b7144c53fd4d 100644 (file)
@@ -6,6 +6,7 @@ abstract class Logger_CallBase implements Logger
     protected $callTypes;
     protected $msns;
 
+    public $debug = false;
 
     /**
      * Create a new call logger.
@@ -33,9 +34,11 @@ abstract class Logger_CallBase implements Logger
     protected function hasValidType($call)
     {
         if ($call->type == CallMonitor_Call::INCOMING && $this->callTypes == 'o') {
+            $this->debug('No valid call type (requested: o)');
             return false;
         }
         if ($call->type == CallMonitor_Call::OUTGOING && $this->callTypes == 'i') {
+            $this->debug('No valid call type (requested: i)');
             return false;
         }
 
@@ -56,6 +59,7 @@ abstract class Logger_CallBase implements Logger
         }
         if (count($this->msns) > 0 && !in_array($msn, $this->msns)) {
             //msn shall not be logged
+            $this->debug('No valid MSN (requested: ' . $msn . ')');
             return false;
         }
 
@@ -100,6 +104,13 @@ abstract class Logger_CallBase implements Logger
         return str_pad($number, 12, ' ', STR_PAD_RIGHT);
     }
 
+    protected function debug($msg)
+    {
+        if (!$this->debug) {
+            return;
+        }
+        echo $msg . "\n";
+    }
 }
 
 ?>
index f5da0f98aa1f5e7b8f673564702a4b041b02fe69..81dd63abaab178218059f9d708d029f668d08ce9 100644 (file)
@@ -54,6 +54,8 @@ class Logger_CallDreambox extends Logger_CallBase
     {
         $url = 'http://' . $this->host
             . '/web/message?type=2&timeout=10&text=' . urlencode($msg);
+        $this->debug('Fetch: ' . $url);
+
         exec(
             'curl'
             . ' ' . escapeshellarg($url)