Browse Source

CHG: FindBoxService::getStrTime() to FindBoxService::log2console()

Giancarlo Voci 8 years ago
parent
commit
e03afe504f

+ 4 - 0
.gitignore

@@ -47,6 +47,8 @@ cache
 vendor
 node_modules
 tmp
+src_minified
+import
 
 # Custom for current project
 /bundle.js
@@ -54,3 +56,5 @@ tmp
 *.min.js
 *.min.css
 /cfg/*.bin
+/ui/css/omlink.css
+/ui/js/omlink.min.js

+ 13 - 12
src/OpenMind/FindBox/FindBoxService.php

@@ -26,7 +26,7 @@ class FindBoxService
       try {
         $this->findBoxCore = new FindBoxCoreSystem(...array_values($f3->get('CORE.fb')));
       } catch (\Exception $e) {
-        echo $this->getStrTime() . "Can't find FindBoxCore, retry in 1 second..\n";
+        $this->log2console("Can't find FindBoxCore, retry in 1 second..\n");
         ob_flush();
         flush();
         sleep(1);
@@ -34,9 +34,11 @@ class FindBoxService
     $this->labelToBlink = [];
   }
 
-  private function getStrTime()
+  private function log2console(string $msg)
   {
-    return '[' . date("d/m/Y H:i:s") . '] ';
+    echo '[' . date("d/m/Y H:i:s") . "] FindBoxService: $msg";
+    ob_flush();
+    flush();
   }
 
   private function updateServiceStatus()
@@ -69,13 +71,13 @@ class FindBoxService
           $this->labelToBlink[$qCommand->id] = $qCommand;
           break;
         case Q_BLINK_OFF:
-          echo $this->getStrTime() . "BlinkOff for label {$qCommand->id} requested\n";
+          $this->log2console("BlinkOff for label {$qCommand->id} requested\n");
           $esl = new SmartESL($this->findBoxCore, [$qCommand->id]);
           $esl->BlinkOff();
           unset($this->labelToBlink[$qCommand->id]);
           break;
         case Q_DISPLAY:
-          echo $this->getStrTime() . "Change display for label {$qCommand->id} requested\n";
+          $this->log2console("Change display for label {$qCommand->id} requested\n");
           $esl = new SmartESL($this->findBoxCore, [$qCommand->id]);
           $esl->Display($qCommand->params['templateId'], $qCommand->params['barcode']);
           unset($this->labelToBlink[$qCommand->id]);
@@ -83,7 +85,7 @@ class FindBoxService
       }
       $table->erase();
       $table->next();
-      echo $this->getStrTime() . "Label {$qCommand->id} readed\n";
+      $this->log2console("Label {$qCommand->id} readed\n");
     }
   }
 
@@ -97,7 +99,7 @@ class FindBoxService
   {
     if ($label->operation == Q_SAVEPRODUCT) {
       $this->findBoxCore->SaveProducts($label->id, $label->description, $label->params['dataFields']);
-      echo $this->getStrTime() . "Save product {$label->id}\n";
+      $this->log2console("Save product {$label->id}\n");
       return true;
     }
     return false;
@@ -112,7 +114,7 @@ class FindBoxService
    */
   public function Main($f3)
   {
-    echo $this->getStrTime() . "Starting FindBoxService main loop\n";
+    $this->log2console("Starting FindBoxService main loop\n");
     while (true) {
 
       $this->updateServiceStatus();
@@ -120,14 +122,14 @@ class FindBoxService
       $this->getCurrentQueue();
 
       //echo $this->getStrTime() . 'Label in cache: ' . count($this->labelToBlink) . "     \n";
-      foreach ($this->labelToBlink as $labelId => $label) {
+      foreach($this->labelToBlink as $labelId => $label) {
 
         // Priority 1
         // ----------
         // Force exit and blink off if run time script > MAX_BLINK_TIME_SEC
         $now = time() - $label->tsFirstBlink;
         if ($now > $f3->get('MAX_BLINK_TIME_SEC')) {
-          echo $this->getStrTime() . "Stop label {$label->id} for timeout\n";
+          $this->log2console("Stop label {$label->id} for timeout\n");
           $esl = new SmartESL($this->findBoxCore, [$label->id]);
           $esl->BlinkOff();
           unset($this->labelToBlink[$labelId]);
@@ -141,7 +143,7 @@ class FindBoxService
         /** @var QueueCommand $label */
         $calcDuration = $label->getBlinkDuration();
         if ($blinkEndTime > $calcDuration) {
-          echo $this->getStrTime() . "Auto restart blinking for label $label->id\n";
+          $this->log2console("Auto restart blinking for label $label->id\n");
 
           $esl = new SmartESL($this->findBoxCore, [$label->id]);
           $ledParams = $label->params;
@@ -154,7 +156,6 @@ class FindBoxService
       //echo $this->getStrTime() . "Restart loop                  \n";
       ob_flush();
       flush();
-      //echo $this->getStrTime() . memory_get_usage() . PHP_EOL;
       usleep($f3->get('FINDBOXSERVICE.SLEEPTIME') * 1000);
     }
 

+ 3 - 3
src/OpenMind/System/ErrorHandlers.php

@@ -29,7 +29,7 @@ class ErrorHandlers
 
     $err = $this->f3->get('ERROR');
 
-    $this->WriteLog(join(' - ', array($err['code'], $err['status'], $err['text'])));
+    $this->WriteLog(join(' - ', array($err['code'], $err['status'], $err['text'])), 'd/m/Y H:i:s');
 
     if ($this->f3->get('CLI')) {
       print_r($arrayError);
@@ -63,11 +63,11 @@ class ErrorHandlers
       $class = isset($trace['class']) ? $trace['class'] . ':' : '';
       $line = isset($trace['line']) ? $trace['line'] . ':' : '';
       //$userAgent = '(' . join(', ', $UA) . ')';
-      OMUtils::getInstance()->getLogger()->write("{$line}{$class}{$method} " . str_replace(array("\r", "\n"), '', $logMessage));
+      OMUtils::getInstance()->getLogger()->write("{$line}{$class}{$method} " . str_replace(array("\r", "\n"), '', $logMessage), 'd/m/Y H:i:s');
       return;
     }
 
-    OMUtils::getInstance()->getLogger()->write($logMessage);
+    OMUtils::getInstance()->getLogger()->write($logMessage, 'd/m/Y H:i:s');
   }
 
 }

+ 1 - 1
src/OpenMind/System/Notifications.php

@@ -14,7 +14,7 @@ class Notifications extends Mapper
 {
   const FB_GENERIC = 0x01;
   const FB_IMPORT = 0x02;
-  const FB_NOTALIVE = 11;
+  const FB_NOTALIVE = 0x0B;
   /**
    * If you need custom notification or to simply send a command to client use FB_CUSTOM_NOTIFICATION+xxx where xxx is a number that identify your notification
    */

+ 1 - 0
src/OpenMind/System/OMUtils.php

@@ -88,6 +88,7 @@ class OMUtils
     return \Template::instance()->resolve($strTemplate);
   }
 
+
   /**
    * Load an encrypted file with the method "base64_encode(gzcompress(<path to config.ini>))", save it in a temporary file in temp folder of system and load with F3::config()
    *

+ 1 - 1
ui/header.tpl

@@ -1,4 +1,4 @@
-<nav class="navbar navbar-expand-sm  navbar-dark bg-dark om-shadow">
+<nav class="navbar navbar-expand-sm navbar-dark bg-dark om-shadow">
 	<a href="{{@BASEURL}}/"><img class="img-fluid om-shadow navbar-brand customerlogo" src="{{@LOGO_CUSTOMER}}"/></a>
 	<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#headerMenu" aria-controls="headerMenu" aria-expanded="false" aria-label="Toggle navigation">
 		<span class="navbar-toggler-icon"></span>

+ 0 - 1
ui/js/omlink.js

@@ -118,4 +118,3 @@ $(function () {
   }, 3000);
 });
 
-