diff --git a/.gradle/7.4/executionHistory/executionHistory.bin b/.gradle/7.4/executionHistory/executionHistory.bin index d602970..aff2323 100644 Binary files a/.gradle/7.4/executionHistory/executionHistory.bin and b/.gradle/7.4/executionHistory/executionHistory.bin differ diff --git a/.gradle/7.4/executionHistory/executionHistory.lock b/.gradle/7.4/executionHistory/executionHistory.lock index 3801025..d0c3d93 100644 Binary files a/.gradle/7.4/executionHistory/executionHistory.lock and b/.gradle/7.4/executionHistory/executionHistory.lock differ diff --git a/.gradle/7.4/fileHashes/fileHashes.bin b/.gradle/7.4/fileHashes/fileHashes.bin index 8eed8d4..2cc39f6 100644 Binary files a/.gradle/7.4/fileHashes/fileHashes.bin and b/.gradle/7.4/fileHashes/fileHashes.bin differ diff --git a/.gradle/7.4/fileHashes/fileHashes.lock b/.gradle/7.4/fileHashes/fileHashes.lock index 76aa01f..87b1645 100644 Binary files a/.gradle/7.4/fileHashes/fileHashes.lock and b/.gradle/7.4/fileHashes/fileHashes.lock differ diff --git a/.gradle/7.4/fileHashes/resourceHashesCache.bin b/.gradle/7.4/fileHashes/resourceHashesCache.bin index 86fd23e..6dd32d9 100644 Binary files a/.gradle/7.4/fileHashes/resourceHashesCache.bin and b/.gradle/7.4/fileHashes/resourceHashesCache.bin differ diff --git a/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/.gradle/buildOutputCleanup/buildOutputCleanup.lock index 7659b0e..896ba79 100644 Binary files a/.gradle/buildOutputCleanup/buildOutputCleanup.lock and b/.gradle/buildOutputCleanup/buildOutputCleanup.lock differ diff --git a/.gradle/buildOutputCleanup/outputFiles.bin b/.gradle/buildOutputCleanup/outputFiles.bin index 2f1f075..845d896 100644 Binary files a/.gradle/buildOutputCleanup/outputFiles.bin and b/.gradle/buildOutputCleanup/outputFiles.bin differ diff --git a/.gradle/file-system.probe b/.gradle/file-system.probe index 96d00f2..a9af5b2 100644 Binary files a/.gradle/file-system.probe and b/.gradle/file-system.probe differ diff --git a/.gradle/workspace-id.txt.lock b/.gradle/workspace-id.txt.lock index 222c0f3..026e0d1 100644 Binary files a/.gradle/workspace-id.txt.lock and b/.gradle/workspace-id.txt.lock differ diff --git a/build.gradle b/build.gradle index 8013cc0..0161029 100644 --- a/build.gradle +++ b/build.gradle @@ -3,7 +3,7 @@ plugins { } group 'com.optilog' -version '2022.5.3.1' +version '2022.5.4' repositories { mavenCentral() diff --git a/build/classes/java/main/com/optilog/log/Logger.class b/build/classes/java/main/com/optilog/log/Logger.class index 0fd01f7..9cfbf3c 100644 Binary files a/build/classes/java/main/com/optilog/log/Logger.class and b/build/classes/java/main/com/optilog/log/Logger.class differ diff --git a/build/classes/java/main/com/optilog/log/console/ZipLog.class b/build/classes/java/main/com/optilog/log/console/ZipLog.class index aa71cb5..9d9cb0c 100644 Binary files a/build/classes/java/main/com/optilog/log/console/ZipLog.class and b/build/classes/java/main/com/optilog/log/console/ZipLog.class differ diff --git a/build/classes/java/main/com/optilog/setting/SettingFiles.class b/build/classes/java/main/com/optilog/setting/SettingFiles.class index 83c7187..b783cb2 100644 Binary files a/build/classes/java/main/com/optilog/setting/SettingFiles.class and b/build/classes/java/main/com/optilog/setting/SettingFiles.class differ diff --git a/build/classes/java/test/com/optilog/OptilogTest.class b/build/classes/java/test/com/optilog/OptilogTest.class index 2711d53..45da51f 100644 Binary files a/build/classes/java/test/com/optilog/OptilogTest.class and b/build/classes/java/test/com/optilog/OptilogTest.class differ diff --git a/build/classes/java/test/com/optilog/PerformanceTester.class b/build/classes/java/test/com/optilog/PerformanceTester.class index 3a411b5..393f727 100644 Binary files a/build/classes/java/test/com/optilog/PerformanceTester.class and b/build/classes/java/test/com/optilog/PerformanceTester.class differ diff --git a/build/classes/java/test/com/optilog/Test.class b/build/classes/java/test/com/optilog/Test.class index 6a44457..c61435a 100644 Binary files a/build/classes/java/test/com/optilog/Test.class and b/build/classes/java/test/com/optilog/Test.class differ diff --git a/build/libs/Optilog-Client-2022.5.4.jar b/build/libs/Optilog-Client-2022.5.4.jar new file mode 100644 index 0000000..cb541fd Binary files /dev/null and b/build/libs/Optilog-Client-2022.5.4.jar differ diff --git a/build/reports/tests/test/index.html b/build/reports/tests/test/index.html index 4ff2f02..dd46caf 100644 --- a/build/reports/tests/test/index.html +++ b/build/reports/tests/test/index.html @@ -85,7 +85,7 @@

Classes

Generated by -Gradle 7.4 at 2022年5月27日 下午12:47:24

+Gradle 7.4 at 2022年5月27日 下午8:59:17

diff --git a/build/resources/test/Settings.properties b/build/resources/test/Settings.properties index c91f420..d1030c8 100644 --- a/build/resources/test/Settings.properties +++ b/build/resources/test/Settings.properties @@ -3,14 +3,14 @@ printError=true printWarn=true printDebug=true printFatal=true -#defaultConsolePath=D:\\Program\\Feishu\\app\\assets\\object\\apps\\Intellij-IDEA\\Project\\Optilog-Client\\src\\test\\resources\\logs -Path1=D:\\Program\\Feishu\\app\\assets\\object\\apps\\Intellij-IDEA\\Project\\Optilog-Client\\src\\test\\resources\\logs -Path2=D:\\Program\\Feishu\\app\\assets\\object\\apps\\Intellij-IDEA\\Project\\Optilog-Client\\src\\test\\resources -infoPath=%path1 -errorPath=%path2 -warnPath=%path1 -debugPath=%path1 -fatalPath=%path2 +defaultConsolePath=D:\\Program\\Feishu\\app\\assets\\object\\apps\\Intellij-IDEA\\Project\\Optilog-Client\\src\\test\\resources\\logs +#Path1=D:\\Program\\Feishu\\app\\assets\\object\\apps\\Intellij-IDEA\\Project\\Optilog-Client\\src\\test\\resources\\logs +#Path2=D:\\Program\\Feishu\\app\\assets\\object\\apps\\Intellij-IDEA\\Project\\Optilog-Client\\src\\test\\resources +#infoPath=%path1 +#errorPath=%path2 +#warnPath=%path1 +#debugPath=%path1 +#fatalPath=%path2 consoleInfo=true consoleDebug=true consoleError=true diff --git a/build/resources/test/logs/2022-05-26 15-36-21Log.log b/build/resources/test/logs/2022-05-26 15-36-21Log.log deleted file mode 100644 index 7388788..0000000 --- a/build/resources/test/logs/2022-05-26 15-36-21Log.log +++ /dev/null @@ -1,18 +0,0 @@ -[2022-05-26|15:36:22(01))][com.optilog.OptilogTest main(OptilogTest.java:8)/main] info:---常规输出测试--- -[2022-05-26|15:36:22(03))][com.optilog.OptilogTest main(OptilogTest.java:9)/main] info:infojava.lang.Object@2b9627bc -[2022-05-26|15:36:22(04))][com.optilog.OptilogTest main(OptilogTest.java:10)/main] Error:error -[2022-05-26|15:36:22(04))][com.optilog.OptilogTest main(OptilogTest.java:11)/main] debug:debug32.0 -[2022-05-26|15:36:22(04))][com.optilog.OptilogTest main(OptilogTest.java:12)/main] FATAL:null -[2022-05-26|15:36:22(04))][com.optilog.OptilogTest main(OptilogTest.java:13)/main] FATAL:null -[2022-05-26|15:36:22(05))][com.optilog.OptilogTest main(OptilogTest.java:14)/main] Warning:warnnull -[2022-05-26|15:36:22(05))][com.optilog.OptilogTest main(OptilogTest.java:15)/main] info:---占位符--- -[2022-05-26|15:36:22(06))][com.optilog.OptilogTest main(OptilogTest.java:16)/main] info:1 2 -[2022-05-26|15:36:22(06))][com.optilog.OptilogTest main(OptilogTest.java:17)/main] Error:1 1 -[2022-05-26|15:36:22(06))][com.optilog.OptilogTest main(OptilogTest.java:18)/main] Warning:null -[2022-05-26|15:36:22(06))][com.optilog.OptilogTest main(OptilogTest.java:19)/main] debug:1 2 #3 -[2022-05-26|15:36:22(07))][com.optilog.OptilogTest main(OptilogTest.java:20)/main] FATAL:1 #2 -[2022-05-26|15:36:22(07))][com.optilog.OptilogTest main(OptilogTest.java:21)/main] debug:de -[2022-05-26|15:36:22(07))][com.optilog.OptilogTest test(OptilogTest.java:26)/main] Warning:---变化栈测试--- -[2022-05-26|15:36:22(07))][com.optilog.OptilogTest test(OptilogTest.java:27)/main] info:info(test) -[2022-05-26|15:36:22(08))][com.optilog.OptilogTest test(OptilogTest.java:29)/main] info:$ -[2022-05-26|15:36:22(08))][com.optilog.OptilogTest lambda$test$1(OptilogTest.java:28)/Thread-0] info:hello diff --git a/build/resources/test/logs/2022-05-27 12-40-49Log.log b/build/resources/test/logs/2022-05-27 12-40-49Log.log deleted file mode 100644 index bd522db..0000000 --- a/build/resources/test/logs/2022-05-27 12-40-49Log.log +++ /dev/null @@ -1 +0,0 @@ -[2022-05-27|12:40:49(83))][com.optilog.PerformanceTester main(PerformanceTester.java:9)/main] info:Hello World! diff --git a/build/resources/test/logs/2022-05-27 12-45-22Log.log b/build/resources/test/logs/2022-05-27 12-45-22Log.log deleted file mode 100644 index f0893a0..0000000 --- a/build/resources/test/logs/2022-05-27 12-45-22Log.log +++ /dev/null @@ -1 +0,0 @@ -[2022-05-27|12:45:22(87))][com.optilog.PerformanceTester main(PerformanceTester.java:9)/main] info:Hello World! diff --git a/build/resources/test/logs/2022-05-27 17-37-47Log.log b/build/resources/test/logs/2022-05-27 17-37-47Log.log deleted file mode 100644 index a521bb8..0000000 --- a/build/resources/test/logs/2022-05-27 17-37-47Log.log +++ /dev/null @@ -1,15 +0,0 @@ -[2022-05-27|17:37:47(29))][com.optilog.OptilogTest main(OptilogTest.java:8)/main] info:---常规输出测试--- -[2022-05-27|17:37:47(32))][com.optilog.OptilogTest main(OptilogTest.java:9)/main] info:infojava.lang.Object@65e2dbf3 -[2022-05-27|17:37:47(33))][com.optilog.OptilogTest main(OptilogTest.java:10)/main] Error:error -[2022-05-27|17:37:47(33))][com.optilog.OptilogTest main(OptilogTest.java:11)/main] debug:debug32.0 -[2022-05-27|17:37:47(34))][com.optilog.OptilogTest main(OptilogTest.java:14)/main] Warning:warnnull -[2022-05-27|17:37:47(34))][com.optilog.OptilogTest main(OptilogTest.java:15)/main] info:---占位符--- -[2022-05-27|17:37:47(35))][com.optilog.OptilogTest main(OptilogTest.java:16)/main] info:1 2 -[2022-05-27|17:37:47(35))][com.optilog.OptilogTest main(OptilogTest.java:17)/main] Error:1 1 -[2022-05-27|17:37:47(35))][com.optilog.OptilogTest main(OptilogTest.java:18)/main] Warning:null -[2022-05-27|17:37:47(36))][com.optilog.OptilogTest main(OptilogTest.java:19)/main] debug:1 2 #3 -[2022-05-27|17:37:47(36))][com.optilog.OptilogTest main(OptilogTest.java:21)/main] debug:de -[2022-05-27|17:37:47(36))][com.optilog.OptilogTest test(OptilogTest.java:26)/main] Warning:---变化栈测试--- -[2022-05-27|17:37:47(37))][com.optilog.OptilogTest test(OptilogTest.java:27)/main] info:info(test) -[2022-05-27|17:37:47(37))][com.optilog.OptilogTest test(OptilogTest.java:29)/main] info:$ -[2022-05-27|17:37:47(37))][com.optilog.OptilogTest lambda$test$1(OptilogTest.java:28)/Thread-0] info:hello diff --git a/build/resources/test/logs/2022-05-27 17-38-47Log.log b/build/resources/test/logs/2022-05-27 17-38-47Log.log deleted file mode 100644 index adf904f..0000000 --- a/build/resources/test/logs/2022-05-27 17-38-47Log.log +++ /dev/null @@ -1,7 +0,0 @@ -[2022-05-27|17:38:47(65))][com.optilog.OptilogTest main(OptilogTest.java:8)/main] info:---常规输出测试--- -[2022-05-27|17:38:47(68))][com.optilog.OptilogTest main(OptilogTest.java:9)/main] info:infojava.lang.Object@2b9627bc -[2022-05-27|17:38:47(69))][com.optilog.OptilogTest main(OptilogTest.java:15)/main] info:---占位符--- -[2022-05-27|17:38:47(70))][com.optilog.OptilogTest main(OptilogTest.java:16)/main] info:1 2 -[2022-05-27|17:38:47(71))][com.optilog.OptilogTest test(OptilogTest.java:27)/main] info:info(test) -[2022-05-27|17:38:47(71))][com.optilog.OptilogTest test(OptilogTest.java:29)/main] info:$ -[2022-05-27|17:38:47(71))][com.optilog.OptilogTest lambda$test$1(OptilogTest.java:28)/Thread-0] info:hello diff --git a/build/resources/test/logs/2022-05-27 17-39-51Log.log b/build/resources/test/logs/2022-05-27 17-39-51Log.log deleted file mode 100644 index c5a2770..0000000 --- a/build/resources/test/logs/2022-05-27 17-39-51Log.log +++ /dev/null @@ -1,14 +0,0 @@ -[2022-05-27|17:39:51(05))][com.optilog.Test main(Test.java:8)/main] info: -[2022-05-27|17:39:51(08))][com.optilog.log.Optilog getAllField(Optilog.java:826)/main] info: -class com.optilog.log.Optilog -> com.optilog.log.Optilog@369f73a2: - socket(class java.net.DatagramSocket) = java.net.DatagramSocket@67b92f0a - consoleFileMasterCaution(boolean) = true - alreadyInit(boolean) = true - allSetting(class com.optilog.setting.SettingFiles) = com.optilog.setting.SettingFiles@65e2dbf3 - settingFilePath(class java.lang.String) = %prop -cp /Settings.properties - info(class java.lang.String) = D:\Program\Feishu\app\assets\object\apps\Intellij-IDEA\Project\Optilog-Client\src\test\resources\logs\2022-05-27 17-39-51Log.log - error(class java.lang.String) = - warn(class java.lang.String) = - debug(class java.lang.String) = - fatal(class java.lang.String) = -end diff --git a/build/resources/test/logs/2022-05-27 17-44-00(99)LogPackage.zip b/build/resources/test/logs/2022-05-27 17-44-00(99)LogPackage.zip deleted file mode 100644 index c8f0968..0000000 Binary files a/build/resources/test/logs/2022-05-27 17-44-00(99)LogPackage.zip and /dev/null differ diff --git a/build/resources/test/logs/2022-05-27 17-44-00Log.log b/build/resources/test/logs/2022-05-27 17-44-00Log.log deleted file mode 100644 index a6a742e..0000000 --- a/build/resources/test/logs/2022-05-27 17-44-00Log.log +++ /dev/null @@ -1,14 +0,0 @@ -[2022-05-27|17:44:00(96))][com.optilog.Test main(Test.java:8)/main] info: -[2022-05-27|17:44:00(98))][com.optilog.log.Optilog getAllField(Optilog.java:826)/main] info: -class com.optilog.log.Optilog -> com.optilog.log.Optilog@369f73a2: - socket(class java.net.DatagramSocket) = java.net.DatagramSocket@67b92f0a - consoleFileMasterCaution(boolean) = true - alreadyInit(boolean) = true - allSetting(class com.optilog.setting.SettingFiles) = com.optilog.setting.SettingFiles@65e2dbf3 - settingFilePath(class java.lang.String) = %prop -cp /Settings.properties - info(class java.lang.String) = D:\Program\Feishu\app\assets\object\apps\Intellij-IDEA\Project\Optilog-Client\src\test\resources\logs\2022-05-27 17-44-00Log.log - error(class java.lang.String) = D:\Program\Feishu\app\assets\object\apps\Intellij-IDEA\Project\Optilog-Client\src\test\resources\2022-05-27 17-44-00Log.log - warn(class java.lang.String) = D:\Program\Feishu\app\assets\object\apps\Intellij-IDEA\Project\Optilog-Client\src\test\resources\logs\2022-05-27 17-44-00Log.log - debug(class java.lang.String) = D:\Program\Feishu\app\assets\object\apps\Intellij-IDEA\Project\Optilog-Client\src\test\resources\logs\2022-05-27 17-44-00Log.log - fatal(class java.lang.String) = D:\Program\Feishu\app\assets\object\apps\Intellij-IDEA\Project\Optilog-Client\src\test\resources\2022-05-27 17-44-00Log.log -end diff --git a/build/tmp/compileJava/previous-compilation-data.bin b/build/tmp/compileJava/previous-compilation-data.bin index 754fa12..d92d6a5 100644 Binary files a/build/tmp/compileJava/previous-compilation-data.bin and b/build/tmp/compileJava/previous-compilation-data.bin differ diff --git a/build/tmp/compileTestJava/previous-compilation-data.bin b/build/tmp/compileTestJava/previous-compilation-data.bin index abd4f51..1cef571 100644 Binary files a/build/tmp/compileTestJava/previous-compilation-data.bin and b/build/tmp/compileTestJava/previous-compilation-data.bin differ diff --git a/src/main/java/com/optilog/log/Logger.java b/src/main/java/com/optilog/log/Logger.java index 2b01640..c2aebd2 100644 --- a/src/main/java/com/optilog/log/Logger.java +++ b/src/main/java/com/optilog/log/Logger.java @@ -110,10 +110,10 @@ void logFatal(LogEvent le, Optilog instance) { static void logCommand(String command, Optilog instance) { if (command.equals("%stop -client")) { Client.stop(instance); - } else if (command.equals("%zip")) { - ZipLog.zipAllLog(false, instance); - } else if (command.equals("%zip -d")) { - ZipLog.zipAllLog(true, instance); + } else if (command.startsWith("%zip -d")) { + ZipLog.zipAllLog(true, instance, command.substring(8)); + } else if (command.startsWith("%zip")) { + ZipLog.zipAllLog(false, instance, command.substring(5)); } else { try { throw new InvalidCommandException("Invalid Command '" + command + "' ", new IllegalArgumentException()); diff --git a/src/main/java/com/optilog/log/console/ZipLog.java b/src/main/java/com/optilog/log/console/ZipLog.java index ba26f2f..4e4a70d 100644 --- a/src/main/java/com/optilog/log/console/ZipLog.java +++ b/src/main/java/com/optilog/log/console/ZipLog.java @@ -1,8 +1,6 @@ package com.optilog.log.console; -import com.optilog.log.LogInit; import com.optilog.log.Optilog; -import com.optilog.util.Util; import java.io.File; import java.io.FileOutputStream; @@ -14,172 +12,33 @@ import java.util.zip.ZipOutputStream; public class ZipLog { - public static void zipAllLog(boolean delete, Optilog instance) { - if (!instance.alreadyInit) { - LogInit.initLog(instance.settingFilePath, instance); - } + public static void zipAllLog(boolean delete, Optilog instance, String path) { + File f = new File(path + "//" + DateTimeFormatter.ofPattern("yyyy-MM-dd HH-mm-ss(SS)").format(LocalDateTime.now()) + "LogPackage.zip"); try { - String s = DateTimeFormatter.ofPattern("yyyy-MM-dd HH-mm-ss(SS)").format(LocalDateTime.now()); - File info = new File(instance.info.substring(0, instance.info.length() - (instance.allSetting.fileName.length() + 1)) + "//" + s + "LogPackage.zip"); - File error = new File(instance.error.substring(0, instance.error.length() - (instance.allSetting.fileName.length() + 1)) + "//" + s + "LogPackage.zip"); - File warn = new File(instance.warn.substring(0, instance.warn.length() - (instance.allSetting.fileName.length() + 1)) + "//" + s + "LogPackage.zip"); - File debug = new File(instance.debug.substring(0, instance.debug.length() - (instance.allSetting.fileName.length() + 1)) + "//" + s + "LogPackage.zip"); - File fatal = new File(instance.fatal.substring(0, instance.fatal.length() - (instance.allSetting.fileName.length() + 1)) + "//" + s + "LogPackage.zip"); - try { - if (!info.isFile()) { - if (!info.createNewFile()) { - Util.getOutput().println("Optilog Note:Failed to create zip file!"); - return; - } - } - if (!error.isFile()) { - if (!error.createNewFile()) { - Util.getOutput().println("Optilog Note:Failed to create zip file!"); - return; - } - } - if (!warn.isFile()) { - if (!warn.createNewFile()) { - Util.getOutput().println("Optilog Note:Failed to create zip file!"); - return; - } - } - if (!debug.isFile()) { - if (!debug.createNewFile()) { - Util.getOutput().println("Optilog Note:Failed to create zip file!"); - return; - } - } - if (!fatal.isFile()) { - if (!fatal.createNewFile()) { - Util.getOutput().println("Optilog Note:Failed to create zip file!"); - return; - } - } - } catch (IOException e) { - Util.getOutput().println("Optilog Note:Failed to create zip file!"); - e.printStackTrace(); - return; - } - try (ZipOutputStream output = new ZipOutputStream(new FileOutputStream(info))) { - File[] file = new File(instance.info.substring(0, instance.info.length() - (instance.allSetting.fileName.length() + 1))).listFiles(); - if (file != null) { - for (File f : file) { - if (f.getName().endsWith(".log")) { - output.putNextEntry(new ZipEntry(f.getName())); - output.write(Files.readAllBytes(f.toPath())); - output.closeEntry(); - if (delete) { - if (!f.delete()) { - instance.warn("Optilog Note:Delete #1 failed!", f.getName()); - } - } - } - } - } else { - instance.info("Optilog Note:No log file in info file path."); - } - } catch (IOException e) { - instance.error("Optilog Note:Failed to pack log file.", e); - } - - if (!error.isFile()) { - try (ZipOutputStream output = new ZipOutputStream(new FileOutputStream(error))) { - File[] file = new File(instance.error.substring(0, instance.error.length() - (instance.allSetting.fileName.length() + 1))).listFiles(); - if (file != null) { - for (File f : file) { - if (f.getName().endsWith(".log")) { - output.putNextEntry(new ZipEntry(f.getName())); - output.write(Files.readAllBytes(f.toPath())); - output.closeEntry(); - if (delete) { - if (!f.delete()) { - instance.warn("Optilog Note:Delete #1 failed!", f.getName()); - } - } - } - } - } else { - instance.info("Optilog Note:No log file in error file path."); - } - } catch (IOException e) { - instance.error("Optilog Note:Failed to pack log file.", e); - } - } - - if (!warn.isFile()) { - try (ZipOutputStream output = new ZipOutputStream(new FileOutputStream(warn))) { - File[] file = new File(instance.warn.substring(0, instance.warn.length() - (instance.allSetting.fileName.length() + 1))).listFiles(); - if (file != null) { - for (File f : file) { - if (f.getName().endsWith(".log")) { - output.putNextEntry(new ZipEntry(f.getName())); - output.write(Files.readAllBytes(f.toPath())); - output.closeEntry(); - if (delete) { - if (!f.delete()) { - instance.warn("Optilog Note:Delete #1 failed!", f.getName()); - } - } - } - } - } else { - instance.info("Optilog Note:No log file in warn file path."); - } - } catch (IOException e) { - instance.error("Optilog Note:Failed to pack log file.", e); - } - } - - if (!debug.isFile()) { - try (ZipOutputStream output = new ZipOutputStream(new FileOutputStream(debug))) { - File[] file = new File(instance.debug.substring(0, instance.debug.length() - (instance.allSetting.fileName.length() + 1))).listFiles(); - if (file != null) { - for (File f : file) { - if (f.getName().endsWith(".log")) { - output.putNextEntry(new ZipEntry(f.getName())); - output.write(Files.readAllBytes(f.toPath())); - output.closeEntry(); - if (delete) { - if (!f.delete()) { - instance.warn("Optilog Note:Delete #1 failed!", f.getName()); - } - } - } - } - } else { - instance.info("Optilog Note:No log file in debug file path."); - } - } catch (IOException e) { - instance.error("Optilog Note:Failed to pack log file.", e); - } - } - - if (!fatal.isFile()) { - try (ZipOutputStream output = new ZipOutputStream(new FileOutputStream(fatal))) { - File[] file = new File(instance.fatal.substring(0, instance.fatal.length() - (instance.allSetting.fileName.length() + 1))).listFiles(); - if (file != null) { - for (File f : file) { - if (f.getName().endsWith(".log")) { - output.putNextEntry(new ZipEntry(f.getName())); - output.write(Files.readAllBytes(f.toPath())); - output.closeEntry(); - if (delete) { - if (!f.delete()) { - instance.warn("Optilog Note:Delete #1 failed!", f.getName()); - } - } - } + f.createNewFile(); + } catch (IOException e) { + instance.warn("Optilog Note: Failed to create log package zip."); + return; + } + + try (ZipOutputStream output = new ZipOutputStream(new FileOutputStream(f))) { + File[] file = new File(path).listFiles(); + if (file != null) { + for (File fff : file) { + if (fff.getName().endsWith(".log")) { + output.putNextEntry(new ZipEntry(fff.getName())); + output.write(Files.readAllBytes(fff.toPath())); + output.closeEntry(); + if (delete) { + fff.delete(); } - } else { - instance.info("Optilog Note:No log file in fatal file path."); } - } catch (IOException e) { - instance.error("Optilog Note:Failed to pack log file.", e); } + } else { + instance.info("Optilog Note:No log file in fatal file path."); } - } catch (StringIndexOutOfBoundsException e) { - Util.getOutput().println("Please set 4 xxxxPath in setting files!"); + } catch (IOException e) { + instance.error("Optilog Note:Failed to pack log file.", e); } } } diff --git a/src/main/java/com/optilog/setting/SettingFiles.java b/src/main/java/com/optilog/setting/SettingFiles.java index 4b7b4c0..56ab96a 100644 --- a/src/main/java/com/optilog/setting/SettingFiles.java +++ b/src/main/java/com/optilog/setting/SettingFiles.java @@ -6,6 +6,7 @@ import com.optilog.util.Util; import com.optilog.util.exception.ConfigureException; +import java.io.File; import java.io.IOException; import java.io.InputStream; import java.nio.charset.StandardCharsets; @@ -169,4 +170,85 @@ private static String readAsString(InputStream input) throws IOException { } return sb.toString(); } + + public static void generateJsonSettings(String path) { + File f = new File(path + "//Setting.json"); + try { + if (!f.createNewFile()) { + throw new IOException(); + } + } catch (IOException e) { + e.printStackTrace(); + } + try { + Files.writeString(f.toPath(), "{\n" + + " \"printInfo\": true,\n" + + " \"printError\": true,\n" + + " \"printWarn\": true,\n" + + " \"printDebug\": true,\n" + + " \"printFatal\": true,\n" + + " \"defaultConsolePath\": \"\",\n" + + " \"consoleInfo\": false,\n" + + " \"consoleDebug\": false,\n" + + " \"consoleError\": false,\n" + + " \"consoleWarn\": false,\n" + + " \"consoleFatal\": false,\n" + + " \"infoSendToServer\": false,\n" + + " \"errorSendToServer\": false,\n" + + " \"warnSendToServer\": false,\n" + + " \"debugSendToServer\": false,\n" + + " \"fatalSendToServer\": false,\n" + + " \"startClient\": false,\n" + + " \"socketNumber\": 65535,\n" + + " \"packingFormat\": \"[%yyyy-%MM-%dd|%HH:%mm:%ss(%SS))][%class %method(%file:%line)/%thread] %level:%msg\",\n" + + " \"fileName\": \"%timeLog(Client).log\",\n" + + " \"host\": \"localhost\"\n" + + "}", StandardCharsets.UTF_8); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public static void generatePropertiesSettings(String path) { + File f = new File(path + "//Setting.properties"); + try { + if (!f.createNewFile()) { + throw new IOException(); + } + } catch (IOException e) { + e.printStackTrace(); + } + try { + Files.writeString(f.toPath(), "printInfo=true\n" + + "printError=true\n" + + "printWarn=true\n" + + "printDebug=true\n" + + "printFatal=true\n" + + "defaultConsolePath=\n" + + "#Path1=\n" + + "#Path2=\n" + + "#infoPath=%path1\n" + + "#errorPath=%path2\n" + + "#warnPath=%path1\n" + + "#debugPath=%path1\n" + + "#fatalPath=%path2\n" + + "consoleInfo=false\n" + + "consoleDebug=false\n" + + "consoleError=false\n" + + "consoleWarn=false\n" + + "consoleFatal=false\n" + + "infoSendToServer=false\n" + + "errorSendToServer=false\n" + + "warnSendToServer=false\n" + + "debugSendToServer=false\n" + + "fatalSendToServer=false\n" + + "startClient=false\n" + + "socketNumber=65535\n" + + "packingFormat=[%yyyy-%MM-%dd|%HH:%mm:%ss(%SS))][%class %method(%file:%line)/%thread] %level:%msg\n" + + "fileName=%timeLog.log\n" + + "host=localhost", StandardCharsets.UTF_8); + } catch (IOException e) { + e.printStackTrace(); + } + } } diff --git a/src/test/java/com/optilog/OptilogTest.java b/src/test/java/com/optilog/OptilogTest.java index d89db78..a1d5390 100644 --- a/src/test/java/com/optilog/OptilogTest.java +++ b/src/test/java/com/optilog/OptilogTest.java @@ -20,6 +20,7 @@ public static void main(String[] args) { log.fatal("#1 ##2", "1", "2"); log.debug("#1", () -> "de"); test(log); + log.command("%zip D:\\Program\\Feishu\\app\\assets\\object\\apps\\Intellij-IDEA\\Project\\Optilog-Client\\src\\test\\resources\\logs"); } private static void test(Log log) { @@ -27,5 +28,7 @@ private static void test(Log log) { log.info("info(test)"); new Thread(() -> log.info("hello")).start(); log.info("$"); + Log log2 = Log.initLog(""); + log2.info("log2"); } } diff --git a/src/test/java/com/optilog/PerformanceTester.java b/src/test/java/com/optilog/PerformanceTester.java index 40e8d42..39affb9 100644 --- a/src/test/java/com/optilog/PerformanceTester.java +++ b/src/test/java/com/optilog/PerformanceTester.java @@ -1,12 +1,9 @@ package com.optilog; -import com.optilog.log.Log; - public class PerformanceTester { public static void main(String[] args) { long l = System.currentTimeMillis(); - Log log = Log.initLog("%prop -cp /Settings.properties"); - log.info("Hello World!"); + System.out.println(System.currentTimeMillis() - l); } } diff --git a/src/test/java/com/optilog/Test.java b/src/test/java/com/optilog/Test.java index 62de6fc..7048803 100644 --- a/src/test/java/com/optilog/Test.java +++ b/src/test/java/com/optilog/Test.java @@ -1,13 +1,8 @@ package com.optilog; -import com.optilog.log.Log; - public class Test { public static void main(String[] args) { - Log log = Log.initLog("%prop -cp /Settings.properties"); - log.info(""); - log.getAllField(log); - log.command("%zip"); + } } diff --git a/src/test/resources/2022-05-27 17-44-19Log.log b/src/test/resources/2022-05-27 17-44-19Log.log deleted file mode 100644 index 9246cd8..0000000 --- a/src/test/resources/2022-05-27 17-44-19Log.log +++ /dev/null @@ -1,5 +0,0 @@ -[2022-05-27|17:44:19(86))][com.optilog.OptilogTest main(OptilogTest.java:10)/main] Error:error -[2022-05-27|17:44:19(86))][com.optilog.OptilogTest main(OptilogTest.java:12)/main] FATAL:null -[2022-05-27|17:44:19(87))][com.optilog.OptilogTest main(OptilogTest.java:13)/main] FATAL:null -[2022-05-27|17:44:19(88))][com.optilog.OptilogTest main(OptilogTest.java:17)/main] Error:1 1 -[2022-05-27|17:44:19(89))][com.optilog.OptilogTest main(OptilogTest.java:20)/main] FATAL:1 #2 diff --git a/src/test/resources/Settings.properties b/src/test/resources/Settings.properties index c91f420..d1030c8 100644 --- a/src/test/resources/Settings.properties +++ b/src/test/resources/Settings.properties @@ -3,14 +3,14 @@ printError=true printWarn=true printDebug=true printFatal=true -#defaultConsolePath=D:\\Program\\Feishu\\app\\assets\\object\\apps\\Intellij-IDEA\\Project\\Optilog-Client\\src\\test\\resources\\logs -Path1=D:\\Program\\Feishu\\app\\assets\\object\\apps\\Intellij-IDEA\\Project\\Optilog-Client\\src\\test\\resources\\logs -Path2=D:\\Program\\Feishu\\app\\assets\\object\\apps\\Intellij-IDEA\\Project\\Optilog-Client\\src\\test\\resources -infoPath=%path1 -errorPath=%path2 -warnPath=%path1 -debugPath=%path1 -fatalPath=%path2 +defaultConsolePath=D:\\Program\\Feishu\\app\\assets\\object\\apps\\Intellij-IDEA\\Project\\Optilog-Client\\src\\test\\resources\\logs +#Path1=D:\\Program\\Feishu\\app\\assets\\object\\apps\\Intellij-IDEA\\Project\\Optilog-Client\\src\\test\\resources\\logs +#Path2=D:\\Program\\Feishu\\app\\assets\\object\\apps\\Intellij-IDEA\\Project\\Optilog-Client\\src\\test\\resources +#infoPath=%path1 +#errorPath=%path2 +#warnPath=%path1 +#debugPath=%path1 +#fatalPath=%path2 consoleInfo=true consoleDebug=true consoleError=true diff --git a/src/test/resources/logs/2022-05-26 15-36-21Log.log b/src/test/resources/logs/2022-05-26 15-36-21Log.log deleted file mode 100644 index 7388788..0000000 --- a/src/test/resources/logs/2022-05-26 15-36-21Log.log +++ /dev/null @@ -1,18 +0,0 @@ -[2022-05-26|15:36:22(01))][com.optilog.OptilogTest main(OptilogTest.java:8)/main] info:---常规输出测试--- -[2022-05-26|15:36:22(03))][com.optilog.OptilogTest main(OptilogTest.java:9)/main] info:infojava.lang.Object@2b9627bc -[2022-05-26|15:36:22(04))][com.optilog.OptilogTest main(OptilogTest.java:10)/main] Error:error -[2022-05-26|15:36:22(04))][com.optilog.OptilogTest main(OptilogTest.java:11)/main] debug:debug32.0 -[2022-05-26|15:36:22(04))][com.optilog.OptilogTest main(OptilogTest.java:12)/main] FATAL:null -[2022-05-26|15:36:22(04))][com.optilog.OptilogTest main(OptilogTest.java:13)/main] FATAL:null -[2022-05-26|15:36:22(05))][com.optilog.OptilogTest main(OptilogTest.java:14)/main] Warning:warnnull -[2022-05-26|15:36:22(05))][com.optilog.OptilogTest main(OptilogTest.java:15)/main] info:---占位符--- -[2022-05-26|15:36:22(06))][com.optilog.OptilogTest main(OptilogTest.java:16)/main] info:1 2 -[2022-05-26|15:36:22(06))][com.optilog.OptilogTest main(OptilogTest.java:17)/main] Error:1 1 -[2022-05-26|15:36:22(06))][com.optilog.OptilogTest main(OptilogTest.java:18)/main] Warning:null -[2022-05-26|15:36:22(06))][com.optilog.OptilogTest main(OptilogTest.java:19)/main] debug:1 2 #3 -[2022-05-26|15:36:22(07))][com.optilog.OptilogTest main(OptilogTest.java:20)/main] FATAL:1 #2 -[2022-05-26|15:36:22(07))][com.optilog.OptilogTest main(OptilogTest.java:21)/main] debug:de -[2022-05-26|15:36:22(07))][com.optilog.OptilogTest test(OptilogTest.java:26)/main] Warning:---变化栈测试--- -[2022-05-26|15:36:22(07))][com.optilog.OptilogTest test(OptilogTest.java:27)/main] info:info(test) -[2022-05-26|15:36:22(08))][com.optilog.OptilogTest test(OptilogTest.java:29)/main] info:$ -[2022-05-26|15:36:22(08))][com.optilog.OptilogTest lambda$test$1(OptilogTest.java:28)/Thread-0] info:hello diff --git a/src/test/resources/logs/2022-05-27 12-40-49Log.log b/src/test/resources/logs/2022-05-27 12-40-49Log.log deleted file mode 100644 index bd522db..0000000 --- a/src/test/resources/logs/2022-05-27 12-40-49Log.log +++ /dev/null @@ -1 +0,0 @@ -[2022-05-27|12:40:49(83))][com.optilog.PerformanceTester main(PerformanceTester.java:9)/main] info:Hello World! diff --git a/src/test/resources/logs/2022-05-27 12-45-22Log.log b/src/test/resources/logs/2022-05-27 12-45-22Log.log deleted file mode 100644 index f0893a0..0000000 --- a/src/test/resources/logs/2022-05-27 12-45-22Log.log +++ /dev/null @@ -1 +0,0 @@ -[2022-05-27|12:45:22(87))][com.optilog.PerformanceTester main(PerformanceTester.java:9)/main] info:Hello World! diff --git a/src/test/resources/logs/2022-05-27 17-37-47Log.log b/src/test/resources/logs/2022-05-27 17-37-47Log.log deleted file mode 100644 index a521bb8..0000000 --- a/src/test/resources/logs/2022-05-27 17-37-47Log.log +++ /dev/null @@ -1,15 +0,0 @@ -[2022-05-27|17:37:47(29))][com.optilog.OptilogTest main(OptilogTest.java:8)/main] info:---常规输出测试--- -[2022-05-27|17:37:47(32))][com.optilog.OptilogTest main(OptilogTest.java:9)/main] info:infojava.lang.Object@65e2dbf3 -[2022-05-27|17:37:47(33))][com.optilog.OptilogTest main(OptilogTest.java:10)/main] Error:error -[2022-05-27|17:37:47(33))][com.optilog.OptilogTest main(OptilogTest.java:11)/main] debug:debug32.0 -[2022-05-27|17:37:47(34))][com.optilog.OptilogTest main(OptilogTest.java:14)/main] Warning:warnnull -[2022-05-27|17:37:47(34))][com.optilog.OptilogTest main(OptilogTest.java:15)/main] info:---占位符--- -[2022-05-27|17:37:47(35))][com.optilog.OptilogTest main(OptilogTest.java:16)/main] info:1 2 -[2022-05-27|17:37:47(35))][com.optilog.OptilogTest main(OptilogTest.java:17)/main] Error:1 1 -[2022-05-27|17:37:47(35))][com.optilog.OptilogTest main(OptilogTest.java:18)/main] Warning:null -[2022-05-27|17:37:47(36))][com.optilog.OptilogTest main(OptilogTest.java:19)/main] debug:1 2 #3 -[2022-05-27|17:37:47(36))][com.optilog.OptilogTest main(OptilogTest.java:21)/main] debug:de -[2022-05-27|17:37:47(36))][com.optilog.OptilogTest test(OptilogTest.java:26)/main] Warning:---变化栈测试--- -[2022-05-27|17:37:47(37))][com.optilog.OptilogTest test(OptilogTest.java:27)/main] info:info(test) -[2022-05-27|17:37:47(37))][com.optilog.OptilogTest test(OptilogTest.java:29)/main] info:$ -[2022-05-27|17:37:47(37))][com.optilog.OptilogTest lambda$test$1(OptilogTest.java:28)/Thread-0] info:hello diff --git a/src/test/resources/logs/2022-05-27 17-38-47Log.log b/src/test/resources/logs/2022-05-27 17-38-47Log.log deleted file mode 100644 index adf904f..0000000 --- a/src/test/resources/logs/2022-05-27 17-38-47Log.log +++ /dev/null @@ -1,7 +0,0 @@ -[2022-05-27|17:38:47(65))][com.optilog.OptilogTest main(OptilogTest.java:8)/main] info:---常规输出测试--- -[2022-05-27|17:38:47(68))][com.optilog.OptilogTest main(OptilogTest.java:9)/main] info:infojava.lang.Object@2b9627bc -[2022-05-27|17:38:47(69))][com.optilog.OptilogTest main(OptilogTest.java:15)/main] info:---占位符--- -[2022-05-27|17:38:47(70))][com.optilog.OptilogTest main(OptilogTest.java:16)/main] info:1 2 -[2022-05-27|17:38:47(71))][com.optilog.OptilogTest test(OptilogTest.java:27)/main] info:info(test) -[2022-05-27|17:38:47(71))][com.optilog.OptilogTest test(OptilogTest.java:29)/main] info:$ -[2022-05-27|17:38:47(71))][com.optilog.OptilogTest lambda$test$1(OptilogTest.java:28)/Thread-0] info:hello diff --git a/src/test/resources/logs/2022-05-27 17-39-51Log.log b/src/test/resources/logs/2022-05-27 17-39-51Log.log deleted file mode 100644 index c5a2770..0000000 --- a/src/test/resources/logs/2022-05-27 17-39-51Log.log +++ /dev/null @@ -1,14 +0,0 @@ -[2022-05-27|17:39:51(05))][com.optilog.Test main(Test.java:8)/main] info: -[2022-05-27|17:39:51(08))][com.optilog.log.Optilog getAllField(Optilog.java:826)/main] info: -class com.optilog.log.Optilog -> com.optilog.log.Optilog@369f73a2: - socket(class java.net.DatagramSocket) = java.net.DatagramSocket@67b92f0a - consoleFileMasterCaution(boolean) = true - alreadyInit(boolean) = true - allSetting(class com.optilog.setting.SettingFiles) = com.optilog.setting.SettingFiles@65e2dbf3 - settingFilePath(class java.lang.String) = %prop -cp /Settings.properties - info(class java.lang.String) = D:\Program\Feishu\app\assets\object\apps\Intellij-IDEA\Project\Optilog-Client\src\test\resources\logs\2022-05-27 17-39-51Log.log - error(class java.lang.String) = - warn(class java.lang.String) = - debug(class java.lang.String) = - fatal(class java.lang.String) = -end diff --git a/src/test/resources/logs/2022-05-27 17-44-00(99)LogPackage.zip b/src/test/resources/logs/2022-05-27 17-44-00(99)LogPackage.zip deleted file mode 100644 index c8f0968..0000000 Binary files a/src/test/resources/logs/2022-05-27 17-44-00(99)LogPackage.zip and /dev/null differ diff --git a/src/test/resources/logs/2022-05-27 17-44-00Log.log b/src/test/resources/logs/2022-05-27 17-44-00Log.log deleted file mode 100644 index a6a742e..0000000 --- a/src/test/resources/logs/2022-05-27 17-44-00Log.log +++ /dev/null @@ -1,14 +0,0 @@ -[2022-05-27|17:44:00(96))][com.optilog.Test main(Test.java:8)/main] info: -[2022-05-27|17:44:00(98))][com.optilog.log.Optilog getAllField(Optilog.java:826)/main] info: -class com.optilog.log.Optilog -> com.optilog.log.Optilog@369f73a2: - socket(class java.net.DatagramSocket) = java.net.DatagramSocket@67b92f0a - consoleFileMasterCaution(boolean) = true - alreadyInit(boolean) = true - allSetting(class com.optilog.setting.SettingFiles) = com.optilog.setting.SettingFiles@65e2dbf3 - settingFilePath(class java.lang.String) = %prop -cp /Settings.properties - info(class java.lang.String) = D:\Program\Feishu\app\assets\object\apps\Intellij-IDEA\Project\Optilog-Client\src\test\resources\logs\2022-05-27 17-44-00Log.log - error(class java.lang.String) = D:\Program\Feishu\app\assets\object\apps\Intellij-IDEA\Project\Optilog-Client\src\test\resources\2022-05-27 17-44-00Log.log - warn(class java.lang.String) = D:\Program\Feishu\app\assets\object\apps\Intellij-IDEA\Project\Optilog-Client\src\test\resources\logs\2022-05-27 17-44-00Log.log - debug(class java.lang.String) = D:\Program\Feishu\app\assets\object\apps\Intellij-IDEA\Project\Optilog-Client\src\test\resources\logs\2022-05-27 17-44-00Log.log - fatal(class java.lang.String) = D:\Program\Feishu\app\assets\object\apps\Intellij-IDEA\Project\Optilog-Client\src\test\resources\2022-05-27 17-44-00Log.log -end diff --git a/src/test/resources/logs/2022-05-27 17-44-19Log.log b/src/test/resources/logs/2022-05-27 17-44-19Log.log deleted file mode 100644 index 2336c96..0000000 --- a/src/test/resources/logs/2022-05-27 17-44-19Log.log +++ /dev/null @@ -1,13 +0,0 @@ -[2022-05-27|17:44:19(82))][com.optilog.OptilogTest main(OptilogTest.java:8)/main] info:---常规输出测试--- -[2022-05-27|17:44:19(85))][com.optilog.OptilogTest main(OptilogTest.java:9)/main] info:infojava.lang.Object@2b9627bc -[2022-05-27|17:44:19(86))][com.optilog.OptilogTest main(OptilogTest.java:11)/main] debug:debug32.0 -[2022-05-27|17:44:19(87))][com.optilog.OptilogTest main(OptilogTest.java:14)/main] Warning:warnnull -[2022-05-27|17:44:19(88))][com.optilog.OptilogTest main(OptilogTest.java:15)/main] info:---占位符--- -[2022-05-27|17:44:19(88))][com.optilog.OptilogTest main(OptilogTest.java:16)/main] info:1 2 -[2022-05-27|17:44:19(89))][com.optilog.OptilogTest main(OptilogTest.java:18)/main] Warning:null -[2022-05-27|17:44:19(89))][com.optilog.OptilogTest main(OptilogTest.java:19)/main] debug:1 2 #3 -[2022-05-27|17:44:19(89))][com.optilog.OptilogTest main(OptilogTest.java:21)/main] debug:de -[2022-05-27|17:44:19(90))][com.optilog.OptilogTest test(OptilogTest.java:26)/main] Warning:---变化栈测试--- -[2022-05-27|17:44:19(90))][com.optilog.OptilogTest test(OptilogTest.java:27)/main] info:info(test) -[2022-05-27|17:44:19(90))][com.optilog.OptilogTest test(OptilogTest.java:29)/main] info:$ -[2022-05-27|17:44:19(90))][com.optilog.OptilogTest lambda$test$1(OptilogTest.java:28)/Thread-0] info:hello