Browse Source

获取日志存在bug ,正在排查~~~

hl 9 tháng trước cách đây
mục cha
commit
b5f6c85edd
1 tập tin đã thay đổi với 19 bổ sung6 xóa
  1. 19 6
      src/utils/file.js

+ 19 - 6
src/utils/file.js

@@ -98,17 +98,30 @@ function getLastFile(dirPath, number, callback) {
             logger.error(`无法列出目录。`, err);
             logger.error(`无法列出目录。`, err);
             // process.exit(1);
             // process.exit(1);
         } else {
         } else {
-            logger.info(`--------02`,files,dirPath)
+            logger.info(`--------02`, files, dirPath)
             let fileList = [];
             let fileList = [];
-            for (file of files) {
-                logger.info(`--------02..00`,dirPath,file)
+            //提示日志默认是根据日志生成的,拿到的files 也是 按照生成日志排序的,所以
+            // 按照倒叙获取,如果一个文件内容满足num,就不在继续查询,如果不够,继续获取文件
+            for (var i = fileList.length - 1; i >= 0; i--) {
+                var file = fileList[i];
                 const filePath = path.join(dirPath, file);
                 const filePath = path.join(dirPath, file);
-                logger.info(`--------02..111`,filePath)
                 const stats = await fs.promises.stat(filePath);
                 const stats = await fs.promises.stat(filePath);
-                logger.info(`--------02..22222`,stats)
                 fileList.push({name: file, time: stats.mtimeMs});
                 fileList.push({name: file, time: stats.mtimeMs});
-                break
+
+                if (fileList.length > number) {//如果够 number 就不再继续获取文件
+                    break
+                }
             }
             }
+
+            // for (file of files) {
+            //     logger.info(`--------02..00`, dirPath, file)
+            //     const filePath = path.join(dirPath, file);
+            //     logger.info(`--------02..111`, filePath)
+            //     const stats = await fs.promises.stat(filePath);
+            //     logger.info(`--------02..22222`, stats)
+            //     fileList.push({name: file, time: stats.mtimeMs});
+            // }
+
             logger.info(`--------03`)
             logger.info(`--------03`)
             fileList.sort((a, b) => b.time - a.time);
             fileList.sort((a, b) => b.time - a.time);
             logger.info(`--------04`)
             logger.info(`--------04`)