dengsixing 2 settimane fa
parent
commit
0c7e9f90a7

+ 44 - 7
src/main/java/com/fdkankan/contro/service/impl/JmgaServiceImpl.java

@@ -421,18 +421,14 @@ public class JmgaServiceImpl implements IJmgaService {
             //打包服务端日志
             // 获取所有以 modeling-control 开头的目录
             File baseDir = new File(logBasePath);
-            List<File> allFiles = new ArrayList<>();
             File[] modelingDirs = baseDir.listFiles(f ->
                     f.isDirectory() && f.getName().startsWith("modeling-control")
             );
             if (modelingDirs != null) {
                 for (File dir : modelingDirs) {
-                    collectFiles(dir, allFiles);
+                    this.copyLog(dir.getAbsolutePath(), logPath, "info","sql","error");
                 }
             }
-            for (File l : allFiles) {
-                this.copyLog(l.getAbsolutePath(), logPath, "info","sql","error");
-            }
             //打包算法日志
             ScenePlus scenePlus = scenePlusService.getScenePlusByNum(num);
             ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
@@ -514,17 +510,58 @@ public class JmgaServiceImpl implements IJmgaService {
                 if(i > 7){
                     continue level;
                 }
-                String targetPath = file.getAbsolutePath().replace(FileUtil.getParent(serverPath, 1), tmpPath);
+                String targetPath = file.getAbsolutePath().replace(FileUtil.getParent(serverPath, 1) + File.separator, tmpPath);
                 File targetLog = new File(targetPath);
                 targetLog.createNewFile();
                 try (Stream<String> lines = Files.lines(Paths.get(file.getAbsolutePath()), StandardCharsets.UTF_8)) {
                     lines.map(line -> line.replace("公安", "xx").replaceAll(ipv4Pattern, "ip"))
                             .forEach(line -> FileUtil.appendUtf8String(line, targetLog)); // 或者进行其他处理
                 } catch (IOException e) {
-                    e.printStackTrace();
+                    log.warn("写计算控制服务日志报错, file:{}", file.getAbsolutePath(), e);
                 }
             }
         }
     }
 
+    public static void main(String[] args) throws IOException {
+        String logBasePath = "D:\\Downloads\\";
+        File baseDir = new File(logBasePath);
+        File[] modelingDirs = baseDir.listFiles(f ->
+                f.isDirectory() && f.getName().startsWith("modeling-control")
+        );
+        if (modelingDirs != null) {
+            for (File dir : modelingDirs) {
+                String serverPath = dir.getAbsolutePath();
+                String tmpPath = "D:\\Downloads\\temp\\";
+                String[] levels = {"info","error","sql"};
+                level: for (String level : levels) {
+                    String infoPath = serverPath + File.separator + level + File.separator;
+                    List<File> fileList = FileUtil.loopFiles(infoPath);
+                    if(CollUtil.isEmpty(fileList)){
+                        continue;
+                    }
+                    CollUtil.reverse(fileList);
+                    for (File file : fileList) {
+                        int i = fileList.indexOf(file);
+                        if(i > 7){
+                            continue level;
+                        }
+                        String targetPath = file.getAbsolutePath().replace(FileUtil.getParent(serverPath, 1) + File.separator, tmpPath);
+                        File targetLog = new File(targetPath);
+//                targetLog.createNewFile();
+                        try (Stream<String> lines = Files.lines(Paths.get(file.getAbsolutePath()), StandardCharsets.UTF_8)) {
+                            lines.map(line -> line.replace("公安", "xx").replaceAll(ipv4Pattern, "ip"))
+                                    .forEach(line -> FileUtil.appendUtf8String(line, targetLog)); // 或者进行其他处理
+                        } catch (IOException e) {
+                            e.printStackTrace();
+                        }
+                    }
+                }
+            }
+        }
+
+
+
+    }
+
 }