Przeglądaj źródła

add short name to log library

stanley-king 2 lat temu
rodzic
commit
312be08fd0

+ 12 - 4
core/framework/libraries/log.php

@@ -50,6 +50,8 @@ class Log
     private $mPathFileName;
     private $mPathFile;
 
+    private $mShortName;
+
     private static $stInstance = null;
     private function __construct()
     {
@@ -67,6 +69,8 @@ class Log
 
         $this->mPathFileName = '';
         $this->mPathFile = false;
+
+        $this->mShortName = empty(APP_ID) ? '' : APP_ID;
     }
 
     public static function instance()
@@ -77,6 +81,12 @@ class Log
         return self::$stInstance;
     }
 
+    public static function short_name($name)
+    {
+        $pThis = self::instance();
+        $pThis->mShortName = $name;
+    }
+
     public static function start_sql_log()
     {
         $pThis = self::instance();
@@ -170,15 +180,13 @@ class Log
             $pid = posix_getpid();
         }
 
-        $appid = empty(APP_ID) ? '' : APP_ID;
-        $content = "[{$appid} {$pid} {$now}] {$level}: {$message}\r\n";
+        $content = "[{$this->mShortName} {$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';
+        $log_file = BASE_DATA_PATH . '/log/' . date('Ymd', time()) . '-' . $this->mShortName . '.log';
 
         if ($this->mAppFileName != $log_file)
         {

+ 1 - 2
crontab/control/minutes.php

@@ -412,8 +412,7 @@ class minutesControl extends BaseCronControl
     //任务队列处理
     public function taskOp()
     {
-        defined('APP_ID') or define('APP_ID','task');
-        Log::record('xxxx',Log::DEBUG);
+        Log::short_name('task');
 
         $task_manager = new task\manager();
         $task_id = 0;

+ 2 - 0
test/TestRefillBalance.php

@@ -22,6 +22,8 @@ class TestRefillBalance extends TestCase
 
     public function testAddBalance()
     {
+        Log::short_name('testAddBalance');
+        Log::record("xxx",Log::DEBUG);
         $refill_balance = new statistics\refill_balance();
         $refill_balance->add_balance('system', 0, 0, strtotime('2021-12-01'), 'order_time');
     }