debug\ncode optimization
This commit is contained in:
27
moha.php
27
moha.php
@ -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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user