1
0

debug\ncode optimization

This commit is contained in:
2022-01-19 00:22:34 +01:00
parent 11a2253804
commit e4703dafc8
15 changed files with 135 additions and 82 deletions

View File

@ -1,25 +1,11 @@
<?php
$title = "moha";
$testMode = false;
$testMode = true;
cli_set_process_title($title);
file_put_contents("/proc/".getmypid()."/comm",$title);
//Constants
define( "EOL", "\n");
define("Z2M", "zigbee2mqtt");
define("ON", 1);
define("OFF", 0);
define("AUTO", 0);
define("MANUAL", 1);
// log levels
define( "DEBUG", 16); // => 16
define( "INFO", 1); // => 1
define( "NOTICE", 2); // => 2
define( "WARNING", 4); // => 4
define( "ERROR", 8); // => 8
define( "ALERT", 32);
define( "ALL", DEBUG | INFO | NOTICE | WARNING | ERROR | ALERT);
require "constants.php";
declare(ticks = 1);
@ -68,19 +54,20 @@ function notify($message)
function logger($level, $log, $notif = true)
{
global $logFh, $logLevel, $notificationLevel;
global $logFh, $logLevel, $notificationLevel, $logLevels;
//echo "=====>>>> $level => $logLevel => $notificationLevel" . EOL ;
//echo $log .EOL;
$logString = date("c") . ' ' . $logLevels[$level] . " : $log";
if ($level & $logLevel)
{
fwrite($logFh, "$level : $log" . EOL);
print ("$level : $log" . EOL);
fwrite($logFh, $logString . EOL);
print ($logString . EOL);
}
$test = $level & $notificationLevel;
//echo "notif =>" .$notif . EOL;
if (($test != 0) and ($notif === true))
{
if(notify("Moha\n" . $log) === false)
if(notify("Moha\n" . $logString) === false)
{
logger(INFO, _("Notification not sent"), false);
}