Browse Source

修复bug ,日志查看bug

hl 11 months ago
parent
commit
90424c1e04
2 changed files with 8 additions and 8 deletions
  1. 4 8
      src/utils/file.js
  2. 4 0
      src/web.js

+ 4 - 8
src/utils/file.js

@@ -113,14 +113,10 @@ function getLastFile(dirPath, number, callback) {
 function readLastNLines(dirPath, filePathList, n) {
     const fileList = filePathList.map((item) => {
         var filepath = dirPath + "/" + item
-        // 将相对路径转换为绝对路径
-        const directoryPath = path.resolve(filepath);
-        logger.info("日志文件:" + directoryPath)
-        let lines = [""]
-        if (checkFilePath(directoryPath)) {
-            const content = fs.readFileSync(`${filepath}`, "utf8");
-            lines = content.trim().split("\n");
-        }
+
+        logger.info("日志文件:" + filepath)
+        const content = fs.readFileSync(`${filepath}`, "utf8");
+        let lines = content.trim().split("\n");
         return {
             filePath: item,
             lines: lines,

+ 4 - 0
src/web.js

@@ -6,6 +6,7 @@ const file = require('./utils/file')
 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 {getAppMap} = require("./robot");
 const crypto = require('crypto');
@@ -73,6 +74,9 @@ function init() {
         if (port !== -1) {
             var logPath = "./logs" + port
             logger.info(`日志相对地址:${logPath}`)
+            // 将相对路径转换为绝对路径
+            const directoryPath = path.resolve(logPath);
+            file.checkPathSync(directoryPath)
 
             file.getLastFile(logPath, 10, (fileNameList) => {
                 // logger.info('??1:', fileNameList);