1
0

some debugging and separating callbacks of the main program

This commit is contained in:
2022-01-08 11:51:50 +01:00
parent e702d333c8
commit e7618f9d86
6 changed files with 161 additions and 56 deletions

View File

@ -5,11 +5,6 @@ function now()
return new DateTime("now");
}
function signalHandler($signal)
{
endMoha();
}
function notify($message)
{
global $notificationMethods;
@ -21,29 +16,18 @@ function notify($message)
return $result;
}
function logger($level, $log, $notif = true)
{
global $logFh, $logLevel, $notificationLevel;
//echo "=====>>>> $level => $logLevel => $notificationLevel" . EOL ;
//echo $log .EOL;
if ($level & $logLevel)
{
fwrite($logFh, "$level : $log" . EOL);
print ("$level : $log" . EOL);
}
$test = $level & $notificationLevel;
//echo "notif =>" .$notif . EOL;
if (($test != 0) and ($notif === true))
{
if(notify("Moha\n" . $log) === false)
{
logger(INFO, _("Notification not sent"), false);
}
}
}
function mktopic($device)
{
return $device->topic . "/" . $device->friendlyName;
}
logger(DEBUG, _("signal handling"), false);
//signal handling
function signalHandler($signal)
{
endMoha();
}
pcntl_signal(SIGTERM, 'signalHandler');// Termination ('kill' was called)
pcntl_signal(SIGHUP, 'signalHandler'); // Terminal log-out
pcntl_signal(SIGINT, 'signalHandler');
?>