Quellcode durchsuchen

Merge branch 'rmaster' of 39.97.239.116:gyfl/xyzshop into rmaster

ayHaru vor 3 Jahren
Ursprung
Commit
2effd60ea6

+ 133 - 88
core/framework/libraries/log.php

@@ -1,4 +1,5 @@
 <?php
+
 /**
  * 记录日志
  ***/
@@ -22,7 +23,6 @@ class scope_trace
 
 class Log
 {
-    const open_sql = true;
     const SQL = 1;
     const INFO = 2;
     const DEBUG = 3;
@@ -30,21 +30,60 @@ class Log
     const ERR = 5;
     const RUN = 6;
     const WAIT_HANDLE = 10;
-    const cur_level = self::DEBUG;
 
-    private static $log = [];
+    private $mSqlog;
+
+    private $mAppFileName;
+    private $mAppFile;
+
+    private $mOpenAll;
+    private $mAllFileName;
+    private $mAllFile;
+
+    private $mCurLevel;
+    private $mOpenSql;
+
+    private $mPathFileName;
+    private $mPathFile;
+
+    private static $stInstance = null;
+    private function __construct()
+    {
+        $this->mSqlog = false;
+
+        $this->mAppFile = false;
+        $this->mAppFileName = '';
 
-    private static $sqlog = false;
+        $this->mOpenAll = true;
+        $this->mAllFile = false;
+        $this->mAllFileName = '';
+
+        $this->mCurLevel = self::DEBUG;
+        $this->mOpenSql = true;
+
+        $this->mPathFileName = '';
+        $this->mPathFile = false;
+    }
+
+    public static function instance()
+    {
+        if (self::$stInstance == null) {
+            self::$stInstance = new Log();
+        }
+        return self::$stInstance;
+    }
 
     public static function start_sql_log()
     {
-        self::$sqlog = [];
+        $pThis = self::instance();
+        $pThis->mSqlog = [];
     }
 
     public static function sql_log()
     {
-        if (is_array(self::$sqlog)) {
-            return self::$sqlog;
+        $pThis = self::instance();
+        if (is_array($pThis->mSqlog)) {
+            return $pThis->mSqlog;
         } else {
             return [];
         }
@@ -52,74 +91,58 @@ class Log
 
     public static function end_sql_log()
     {
-        self::$sqlog = false;
+        $pThis = self::instance();
+        $pThis->mSqlog = [];
     }
 
     private static function add_sql_log($log)
     {
-        if (is_array(self::$sqlog)) {
-            self::$sqlog[] = $log;
+        $pThis = self::instance();
+        if (is_array($pThis->mSqlog)) {
+            $pThis->mSqlog[] = $log;
         }
     }
 
     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-    static private $cur_path_file_name = '';
-    static private $cur_path_file;
-
-    public static function record_path($content)
+    public static function record($message, $lev = self::ERR)
     {
-        $path_file = BASE_DATA_PATH . '/log/' . date('Ymd', time()) . '_path.log';
-        if (self::$cur_path_file_name != $path_file) {
-            if (self::$cur_path_file != null) {
-                fclose(self::$cur_path_file);
-            }
-            self::$cur_path_file = fopen($path_file, 'a');
-        }
-
-        if (@flock(self::$cur_path_file, LOCK_EX)) {
-            fwrite(self::$cur_path_file, $content);
-            fwrite(self::$cur_path_file, "\r\n");
-            @flock(self::$cur_path_file, LOCK_UN);
-        }
+        self::instance()->doRecord($message, $lev);
     }
 
-    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-    public static function record($message, $lev = self::ERR)
+    private function doRecord($message, $lev = self::ERR)
     {
-        $now = date('Y-m-d H:i:s', time());
-        $pid = posix_getpid();
+        $slevel = $this->get_level($lev);
+        $content = $this->format_msg($message,$slevel);
 
-        if ($lev == self::WAIT_HANDLE) {
-            $level = 'WAIT_HANDLE';
-            $log_file = BASE_DATA_PATH . '/log/' . date('Ymd', time()) . '-wait.log';
-            $content = "[{$pid} {$now}] {$level}: {$message}\r\n";
-            file_put_contents($log_file, $content, FILE_APPEND);
-            return;
+        if ($lev == self::SQL && $this->mOpenSql) {
+            $this->write($content);
+            if($this->mOpenAll) $this->write_all($content);
         }
-
-        if ($lev == self::SQL) {
-            $level = 'SQL';
-            if (self::open_sql) {
-                self::write($message, $level);
-            }
-            return;
-        }
-
-        if ($lev >= self::cur_level && $lev <= self::RUN) {
-            $level = self::get_level($lev);
-            self::write($message, $level);
+        elseif ($lev >= $this->mCurLevel && $lev <= self::RUN) {
+            $this->write($content);
+            if($this->mOpenAll) $this->write_all($content);
         }
 
         if ($lev == self::ERR) {
-            self::msg();
+            $msg = $this->msg();
+            $content = $this->format_msg($msg,$slevel);
+            $this->write($content);
+            if($this->mOpenAll) $this->write_all($content);
         }
     }
 
-    private static $cur_file_name;
-    private static $cur_file = null;
+    private function get_level($lev)
+    {
+        if ($lev == self::SQL) return 'SQL';
+        if ($lev == self::INFO) return 'INFO';
+        if ($lev == self::DEBUG) return 'DEBUG';
+        if ($lev == self::WARING) return 'WARING';
+        if ($lev == self::ERR) return 'ERR';
+        if ($lev == self::RUN) return 'RUN';
+        return 'Unknown';
+    }
 
-    private static function write($message, $level)
+    private function format_msg($message,$level)
     {
         $now = @date('Y-m-d H:i:s', time());
         if(defined('USE_COROUTINE') && USE_COROUTINE === true) {
@@ -132,51 +155,59 @@ class Log
             $pid = posix_getpid();
         }
 
-
         $appid = empty(APP_ID) ? '' : APP_ID;
+        $content = "[{$appid} {$pid} {$now}] {$level}: {$message}\r\n";
+        return $content;
+    }
 
+    private function write($content)
+    {
+        $appid = empty(APP_ID) ? '' : APP_ID;
         $log_file = BASE_DATA_PATH . '/log/' . date('Ymd', time()) . '-' . $appid . '.log';
-        if (self::$cur_file_name != $log_file) {
-            if (self::$cur_file != null) {
-                fclose(self::$cur_file);
+
+        if ($this->mAppFileName != $log_file)
+        {
+            if ($this->mAppFile !== false) {
+                fclose($this->mAppFile);
             }
-            self::$cur_file_name = $log_file;
-            self::$cur_file = fopen($log_file, 'a+');
+
+            $this->mAppFileName = $log_file;
+            $this->mAppFile = fopen($log_file, 'a+');
         }
 
-        $content = "[{$pid} {$now}] {$level}: {$message}\r\n";
-        $ret = fwrite(self::$cur_file, $content);
-        if ($ret === false) {
-            self::$cur_file = fopen($log_file, 'a+');
-            fwrite(self::$cur_file, $content);
+        if ($this->mAppFile !== false) {
+            fwrite($this->mAppFile, $content);
+            fflush($this->mAppFile);
         }
-        fflush(self::$cur_file);
     }
 
-    public static function endl($lev = self::ERR)
+    private function write_all($content)
     {
-        $content = "\r\n";
+        $log_file = BASE_DATA_PATH . '/log/' . date('Ymd', time()) . '.log';
+
+        if ($this->mAllFileName != $log_file)
+        {
+            if ($this->mAllFile !== false) {
+                fclose($this->mAllFile);
+            }
 
-        if ($lev == self::SQL && self::open_sql) {
-            $log_file = BASE_DATA_PATH . '/log/' . date('Ymd', time()) . '.log';
-            file_put_contents($log_file, $content, FILE_APPEND);
-            return;
+            $this->mAllFileName = $log_file;
+            $this->mAllFile = fopen($log_file, 'a+');
         }
 
-        if ($lev >= self::cur_level) {
-            $log_file = BASE_DATA_PATH . '/log/' . date('Ymd', time()) . '.log';
-            file_put_contents($log_file, $content, FILE_APPEND);
+        if ($this->mAllFile !== false) {
+            fwrite($this->mAllFile, $content);
+            fflush($this->mAllFile);
         }
     }
 
-    public static function msg()
+    private function msg()
     {
         $debugInfo = debug_backtrace();
-
-        $stack = "[";
+        $stack = "\t[";
         foreach ($debugInfo as $key => $val) {
             if (array_key_exists("file", $val)) {
-                $stack .= ",file:" . $val["file"];
+                $stack .= "\tfile:" . $val["file"];
             }
             if (array_key_exists("line", $val)) {
                 $stack .= ",line:" . $val["line"];
@@ -184,24 +215,38 @@ class Log
             if (array_key_exists("function", $val)) {
                 $stack .= ",function:" . $val["function"];
             }
+            $stack .= "\r\n";
         }
         $stack .= "]";
 
         return $stack;
     }
 
-    private static function get_level($lev)
+    private function doRecordPath($content)
     {
-        if ($lev == self::INFO) return 'INFO';
-        if ($lev == self::DEBUG) return 'DEBUG';
-        if ($lev == self::WARING) return 'WARING';
-        if ($lev == self::ERR) return 'ERR';
-        if ($lev == self::RUN) return 'RUN';
-        return 'Unknown';
+        $path_file = BASE_DATA_PATH . '/log/' . date('Ymd', time()) . '_path.log';
+        if ($this->mPathFileName != $path_file)
+        {
+            if ($this->mPathFile !== false) {
+                fclose($this->mPathFile);
+            }
+
+            $this->mPathFile = fopen($path_file, 'a');
+        }
+
+        if($this->mPathFile !== false)
+        {
+            if (@flock($this->mPathFile, LOCK_EX)) {
+                fwrite($this->mPathFile, $content);
+                fwrite($this->mPathFile, "\r\n");
+                @flock($this->mPathFile, LOCK_UN);
+            }
+        }
     }
 
-    public static function read()
+    public static function record_path($content)
     {
-        return self::$log;
+        $pThis = self::instance();
+        $pThis->doRecordPath($content);
     }
 }

+ 24 - 26
core/framework/libraries/logex.php

@@ -1,7 +1,26 @@
 <?php
+/**
+ * 记录日志
+ ***/
+defined('InShopNC') or exit('Access Invalid!');
 
+class scope_trace
+{
+    private $mTag;
+
+    public function __construct($tag)
+    {
+        $this->mTag = $tag;
+        Log::record("{$this->mTag} begin----------------------------", Log::DEBUG);
+    }
 
-class LogEx
+    public function __destruct()
+    {
+        Log::record("{$this->mTag} end  ----------------------------", Log::DEBUG);
+    }
+}
+
+class Log
 {
     const open_sql = true;
     const SQL = 1;
@@ -10,31 +29,16 @@ class LogEx
     const WARING = 4;
     const ERR = 5;
     const RUN = 6;
-
     const WAIT_HANDLE = 10;
     const cur_level = self::DEBUG;
 
-    private $log = [];
-    private $sqlog = false;
+    private static $log = [];
 
-    private static $stInstance = null;
-    private function __construct()
-    {
-
-    }
-
-    public static function instance()
-    {
-        if (self::$stInstance == null) {
-            self::$stInstance = new LogEx();
-        }
-        return self::$stInstance;
-    }
+    private static $sqlog = false;
 
     public static function start_sql_log()
     {
         self::$sqlog = [];
-
     }
 
     public static function sql_log()
@@ -48,7 +52,7 @@ class LogEx
 
     public static function end_sql_log()
     {
-        self::$sqlog = [];
+        self::$sqlog = false;
     }
 
     private static function add_sql_log($log)
@@ -94,8 +98,7 @@ class LogEx
             return;
         }
 
-        if ($lev == self::SQL)
-        {
+        if ($lev == self::SQL) {
             $level = 'SQL';
             if (self::open_sql) {
                 self::write($message, $level);
@@ -150,11 +153,6 @@ class LogEx
         fflush(self::$cur_file);
     }
 
-    private function writetofile($curfile)
-    {
-
-    }
-
     public static function endl($lev = self::ERR)
     {
         $content = "\r\n";

+ 0 - 2
crontab/crawl/product_importer.php

@@ -590,7 +590,6 @@ class product_importer
             $shopid = $shop['shop_id'];
             $count = $shop['n'];
 
-            Log::endl(Log::DEBUG);
             Log::record("begin shop_id={$shopid} spu count= {$count}",Log::DEBUG);
 
             $con = array('imported' => 0,'shop_id' => $shopid);
@@ -602,7 +601,6 @@ class product_importer
                 $num_iid = $item['num_iid'];
                 $picnum = $item['picnum'];
 
-                Log::endl(Log::DEBUG);
                 Log::record("handle num_iid={$num_iid} start.\r\n",Log::DEBUG);
 
                 if($this->goods_exist($num_iid)) {

+ 2 - 2
data/config/dev/base.ini.php

@@ -46,8 +46,8 @@ $config['gip'] 		= 0;
 $config['dbdriver'] = 'mysqli';
 $config['tablepre']	= 'lrlz_';
 
-//define('SSH_TUNEL_PROD','local');
-define('SSH_TUNEL_PROD','xyz');
+define('SSH_TUNEL_PROD','local');
+//define('SSH_TUNEL_PROD','xyz');
 //define('SSH_TUNEL_PROD','lingzh');
 
 if(SSH_TUNEL_PROD ==='local') {

+ 4 - 4
helper/refill/policy/chctl.php

@@ -18,9 +18,9 @@ class chctl
         ['quality'=> 2,'name' => 'channel-ctl-phone-fast-limit'],
         ['quality'=> 3,'name' => 'channel-ctl-phone-card-limit'],
         ['quality'=> 4,'name' => 'channel-ctl-phone-third-limit'],
-        ['quality'=> 5,'name' => 'channel-ctl-phone-slow-limit'],
-        ['quality'=> 6,'name' => 'channel-ctl-phone-slow6-limit'],
-        ['quality'=> 7,'name' => 'channel-ctl-phone-slow2-limit'],
+        ['quality'=> 5,'name' => 'channel-ctl-phone-slow-limit'], //24 hour
+        ['quality'=> 6,'name' => 'channel-ctl-phone-slow6-limit'],//6 hour
+        ['quality'=> 7,'name' => 'channel-ctl-phone-slow2-limit'] //2 hour
     ];
 
     public function __construct()
@@ -53,7 +53,7 @@ class chctl
                     $speed = $item['speed'];
 
                     $key = $this->prefix($name,$amount,$card_type,$quality);
-                    Log::record("Load: key={$key} name={$name} amount={$amount} type={$card_type} opened={$opened} sort={$sort} speed={$speed}",Log::DEBUG);
+                    Log::record("Load: key={$key} quality={$quality} name={$name} amount={$amount} type={$card_type} opened={$opened} sort={$sort} speed={$speed}",Log::DEBUG);
                     $this->mSpeedtable[$key] = new ctl_item($name,$card_type,$amount,$speed,$sort,0,$opened,$quality);
                 }
             }

+ 2 - 0
helper/refill/policy/quaility.php

@@ -50,6 +50,8 @@ class Quality
         }
     }
 
+
+
     private function mobile_quality($mchid,$quality,$times,$used_time): array
     {
         if($quality == 0)

+ 1 - 1
racc/control/lzrefill.php

@@ -33,7 +33,7 @@ class lzrefillControl extends lzbaseControl
         }
 
         $card_no = $params['mob'];
-        if(!preg_match('/^1\d{10}$/',$card_no,$matches)) {
+        if(empty($card_no)) {
             return -11;
         }
 

+ 14 - 3
test/TestLog.php

@@ -6,18 +6,29 @@
  * Time: 下午9:16
  */
 
-define('BASE_ROOT_PATH',str_replace('/test','',dirname(__FILE__)));
+use PHPUnit\Framework\TestCase;
+define('APP_ID', 'test');
+define('BASE_ROOT_PATH', str_replace('/test', '', dirname(__FILE__)));
 
+require_once(BASE_ROOT_PATH . '/global.php');
+require_once(BASE_CORE_PATH . '/lrlz.php');
 require_once(BASE_ROOT_PATH . '/fooder.php');
 require_once(BASE_ROOT_PATH . '/helper/statistics/stlog.php');
 
-class TestLog extends PHPUnit_Framework_TestCase
+class TestLog extends TestCase
 {
-    public static function setUpBeforeClass()
+    public static function setUpBeforeClass() : void
     {
         Base::run_util();
     }
 
+    public function testLogNormal()
+    {
+        Log::record("hello world",Log::DEBUG);
+        Log::record("hello world",Log::ERR);
+
+    }
+
 
     public function testPairlog()
     {

Datei-Diff unterdrückt, da er zu groß ist
+ 7 - 0
test/TestRedis.php