Explorar o código

日志查询bug

hl hai 10 meses
pai
achega
b3b5003ed2
Modificáronse 2 ficheiros con 19 adicións e 11 borrados
  1. 2 1
      src/robot.js
  2. 17 10
      src/web.js

+ 2 - 1
src/robot.js

@@ -43,7 +43,8 @@ function getApp(key) {
         errorMessage: "成功",
         threadStartTime: -1,
         status: 0,
-        restartStatus: 0
+        restartStatus: 0,
+        isFilePath:false,
 
     }
     // logger.info(appMap, appMap.has(key));

+ 17 - 10
src/web.js

@@ -7,7 +7,7 @@ const {logger, fileLogger} = require("./utils/logger");
 const {spawn, exec, fork, execSync} = require("child_process");
 const path = require("path");
 
-const {ka} = require("date-fns/locale");
+const {ka, tr} = require("date-fns/locale");
 const {getAppMap} = require("./robot");
 const crypto = require('crypto');
 
@@ -83,10 +83,12 @@ function init() {
         const id = param.id
 
         var port = -1;
+        var isFilePath = false;
         robot.appMap.forEach((value, key) => {
             // logger.info(JSON.stringify(value))
             if (value.id + "" === id + "") {
                 port = value.port
+                isFilePath = value.isFilePath
             }
         })
 
@@ -95,16 +97,21 @@ function init() {
             var logPath = "./logs" + port
             // 将相对路径转换为绝对路径
             const directoryPath = path.resolve(logPath);
-            if (file.checkPathSync(directoryPath)) {
-                logger.info(`日志相对地址:${logPath}`)
-
-                file.getLastFile(logPath, 10, (fileNameList) => {
-                    logger.info('??1:', fileNameList);
-                    result = file.readLastNLines(logPath, fileNameList, n);
-                    // logger.info('?????:', result);
-                    res.send({'code': 200, 'data': result, "message": "SUCCESS"});
-                });
+            if (isFilePath === false) {
+                if (file.checkPathSync(directoryPath)) {
+                   var app_demo =  robot.getApp(value.id + "");
+                    app_demo.isFilePath = true
+                }
             }
+
+            logger.info(`日志相对地址:${logPath}`)
+
+            file.getLastFile(logPath, 10, (fileNameList) => {
+                logger.info('??1:', fileNameList);
+                result = file.readLastNLines(logPath, fileNameList, n);
+                // logger.info('?????:', result);
+                res.send({'code': 200, 'data': result, "message": "SUCCESS"});
+            });
         } else {
             res.send({'code': 200, 'data': result, "message": "SUCCESS"});
         }