浏览代码

将日志 与 机器人状态详情进行缓存,

hl 3 周之前
父节点
当前提交
c2a4afbb9a
共有 2 个文件被更改,包括 6 次插入6 次删除
  1. 4 4
      src/Interval.js
  2. 2 2
      src/utils/file.js

+ 4 - 4
src/Interval.js

@@ -109,14 +109,14 @@ function cacheLogs() {
                 const jsonString = JSON.stringify(messlist);
                 const byteSize = Buffer.byteLength(jsonString, 'utf8');
                 const megabyteSize = byteSize / (1024 * 1024);
-                logger.info(`~~~缓存日志${value.id}--占用大小:${megabyteSize} M`)
+                logger.info(`~~~缓存日志${value.id}--占用大小:${megabyteSize.toFixed(6)} M`)
                 try {
                     var logPath = "./logs" + port
-                    logger.info(`访问-日志相对目录:${logPath}`)
+                    // logger.info(`访问-日志相对目录:${logPath}`)
                     const directoryPath = path.resolve(logPath);
                     file.checkPathSync(directoryPath)
                     file.getLastFile(logPath, 3, (fileNameList, _) => {
-                        logger.info('-----文件:', fileNameList);
+                        // logger.info('-----文件:', fileNameList);
                         file.getLatestLogEntries(logPath, fileNameList.reverse(), n)
                             .then((result) => {
                                 if (messlist.length === 0) {
@@ -152,7 +152,7 @@ function cachePredictorState() {
                 const jsonString = JSON.stringify(predictorState);
                 const byteSize = Buffer.byteLength(jsonString, 'utf8');
                 const megabyteSize = byteSize / (1024 * 1024);
-                logger.info(`~~~缓存机器人状态详情${value.id}--占用大小:${megabyteSize} M`)
+                logger.info(`~~~缓存机器人状态详情${value.id}--占用大小:${megabyteSize.toFixed(6)} M`)
                 var accUrl = "http://127.0.0.1:" + port
                 http.request_get(`${accUrl}/predictor_state`, {...config.headers})
                     .then((data) => {

+ 2 - 2
src/utils/file.js

@@ -244,7 +244,7 @@ async function getLatestLogEntries(dirPath, logFiles, requiredLogs = 100) {
         for (const file of logFiles) {
             // 创建文件流
             const filepath = `${dirPath}/${file}`;
-            logger.info('文件~~~', filepath);
+            // logger.info('文件~~~', filepath);
 
             // const readStream = fs.createReadStream(filepath, { highWaterMark: 2 * 1024 * 1024 }); // 每次读取10MB
             // let buffer = '';
@@ -298,7 +298,7 @@ async function getLatestLogEntries(dirPath, logFiles, requiredLogs = 100) {
             // 文件信息
             const stats = fs.statSync(filepath); // 获取文件信息
             let position = stats.size; // 从文件末尾开始
-            const chunkSize = 1 * 1024 * 1024; // 每次读取1MB
+            const chunkSize = 5 * 1024 * 1024; // 每次读取5MB
 
             // 文件读取方式
             while (position > 0 && logs.length < MAX_LOGS) {