aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Weiske <cweiske@cweiske.de>2019-03-13 17:01:30 +0100
committerChristian Weiske <cweiske@cweiske.de>2019-03-13 17:01:30 +0100
commit6ec5a125940846a9f7f1bb31d55b19e044db2c09 (patch)
treef7ec307cee6309d6b91783b23dfe616e8ba40cbe /src
parentd0ff3140a682f3adfd906bdb7ef116ba830ceeec (diff)
downloadauerswald-callnotifier-6ec5a125940846a9f7f1bb31d55b19e044db2c09.tar.gz
auerswald-callnotifier-6ec5a125940846a9f7f1bb31d55b19e044db2c09.zip
Add debug message output to call loggers
Diffstat (limited to 'src')
-rw-r--r--src/callnotifier/CLI.php4
-rw-r--r--src/callnotifier/Log.php11
-rw-r--r--src/callnotifier/Logger/CallBase.php11
-rw-r--r--src/callnotifier/Logger/CallDreambox.php2
4 files changed, 25 insertions, 3 deletions
diff --git a/src/callnotifier/CLI.php b/src/callnotifier/CLI.php
index 0b8ae60..564a5f5 100644
--- a/src/callnotifier/CLI.php
+++ b/src/callnotifier/CLI.php
@@ -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
+?>
diff --git a/src/callnotifier/Log.php b/src/callnotifier/Log.php
index d2ee0c8..a831066 100644
--- a/src/callnotifier/Log.php
+++ b/src/callnotifier/Log.php
@@ -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);
}
}
diff --git a/src/callnotifier/Logger/CallBase.php b/src/callnotifier/Logger/CallBase.php
index 31ad0bc..2a1d3e8 100644
--- a/src/callnotifier/Logger/CallBase.php
+++ b/src/callnotifier/Logger/CallBase.php
@@ -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";
+ }
}
?>
diff --git a/src/callnotifier/Logger/CallDreambox.php b/src/callnotifier/Logger/CallDreambox.php
index f5da0f9..81dd63a 100644
--- a/src/callnotifier/Logger/CallDreambox.php
+++ b/src/callnotifier/Logger/CallDreambox.php
@@ -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)