Skip to content

Commit fe2a039

Browse files
committed
2022.5.1-Client(add zip,fix bugs)
1 parent b43b1df commit fe2a039

29 files changed

+115
-138
lines changed
Binary file not shown.
Binary file not shown.

.gradle/7.4/fileHashes/fileHashes.bin

2.83 KB
Binary file not shown.
0 Bytes
Binary file not shown.
1.83 KB
Binary file not shown.
Binary file not shown.

.gradle/file-system.probe

0 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
284 Bytes
Binary file not shown.

build/resources/test/Settings.properties

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,7 @@ printError=true
33
printWarn=true
44
printDebug=true
55
printFatal=true
6-
#defaultConsolePath=D:\\Program\\Feishu\\app\\assets\\object\\apps\\Intellij-IDEA\\Project\\Optilog-Client\\src\\test\\resources\\logs
7-
Path1=D:\\Program\\Feishu\\app\\assets\\object\\apps\\Intellij-IDEA\\Project\\Optilog-Client\\src\\test\\resources\\logs
8-
Path2=D:\\Program\\Feishu\\app\\assets\\object\\apps\\Intellij-IDEA\\Project\\Optilog-Client\\src\\test\\resources
9-
infoPath=%path1
10-
errorPath=%path2
11-
warnPath=%path1
12-
debugPath=%path1
13-
fatalPath=%path2
6+
defaultConsolePath=D:\\Program\\Feishu\\app\\assets\\object\\apps\\Intellij-IDEA\\Project\\Optilog-Client\\src\\test\\resources\\logs
147
consoleInfo=true
158
consoleDebug=true
169
consoleError=true
@@ -24,4 +17,4 @@ fatalSendToServer=true
2417
startClient=true
2518
socketNumber=65535
2619
packingFormat=[%yyyy-%MM-%dd|%HH:%mm:%ss(%SS))][%class %method(%file:%line)/%thread] %level:%msg
27-
fileName=Log.log
20+
fileName=%timeLog.log

build/resources/test/logs/2022-05-16 12-45-42Log(Client).log

Lines changed: 0 additions & 1 deletion
This file was deleted.

build/resources/test/logs/2022-05-19 17-15-35Log(Client).log

Lines changed: 0 additions & 15 deletions
This file was deleted.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

src/main/java/com/optilog/log/LogInit.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
public class LogInit {
1414
@OnlyInInit
15-
protected static void initLog(String settingFilePath, Optilog instance) {
15+
public static void initLog(String settingFilePath, Optilog instance) {
1616
try {
1717
Class.forName("com.google.gson.Gson");
1818
} catch (ClassNotFoundException e) {

src/main/java/com/optilog/log/Optilog.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
public class Optilog implements Log {
1010
public DatagramSocket socket;
1111
public boolean consoleFileMasterCaution = true;
12-
boolean alreadyInit;
12+
public boolean alreadyInit;
1313

1414
public SettingFiles allSetting;
1515

16-
String settingFilePath = "";
16+
public String settingFilePath = "";
1717

1818
public String info = "";
1919
public String error = "";
Lines changed: 103 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.optilog.log.console;
22

3+
import com.optilog.log.LogInit;
34
import com.optilog.log.Optilog;
4-
import com.optilog.util.Debugging;
55
import com.optilog.util.Util;
66

77
import java.io.File;
@@ -13,44 +13,55 @@
1313
import java.util.zip.ZipEntry;
1414
import java.util.zip.ZipOutputStream;
1515

16-
@Debugging // TODO
1716
public class ZipLog {
1817
public static void zipAllLog(boolean delete, Optilog instance) {
18+
if (!instance.alreadyInit) {
19+
LogInit.initLog(instance.settingFilePath, instance);
20+
}
1921
String s = DateTimeFormatter.ofPattern("yyyy-MM-dd HH-mm-ss(SS)").format(LocalDateTime.now());
20-
File info = new File(instance.info + s + "LogPackage.zip");
21-
File error = new File(instance.error + s + "LogPackage.zip");
22-
File warn = new File(instance.warn + s + "LogPackage.zip");
23-
File debug = new File(instance.debug + s + "LogPackage.zip");
24-
File fatal = new File(instance.fatal + s + "LogPackage.zip");
22+
File info = new File(instance.info.substring(0, instance.info.length() - (instance.allSetting.fileName.length() + 1)) + "//" + s + "LogPackage.zip");
23+
File error = new File(instance.error.substring(0, instance.error.length() - (instance.allSetting.fileName.length() + 1)) + "//" + s + "LogPackage.zip");
24+
File warn = new File(instance.warn.substring(0, instance.warn.length() - (instance.allSetting.fileName.length() + 1)) + "//" + s + "LogPackage.zip");
25+
File debug = new File(instance.debug.substring(0, instance.debug.length() - (instance.allSetting.fileName.length() + 1)) + "//" + s + "LogPackage.zip");
26+
File fatal = new File(instance.fatal.substring(0, instance.fatal.length() - (instance.allSetting.fileName.length() + 1)) + "//" + s + "LogPackage.zip");
2527
try {
26-
if (!info.createNewFile()) {
27-
Util.getOutput().println("Optilog Note:Failed to create zip file!");
28-
return;
28+
if (!info.isFile()) {
29+
if (!info.createNewFile()) {
30+
Util.getOutput().println("Optilog Note:Failed to create zip file!");
31+
return;
32+
}
2933
}
30-
if (!error.createNewFile()) {
31-
Util.getOutput().println("Optilog Note:Failed to create zip file!");
32-
return;
34+
if (!error.isFile()) {
35+
if (!error.createNewFile()) {
36+
Util.getOutput().println("Optilog Note:Failed to create zip file!");
37+
return;
38+
}
3339
}
34-
if (!warn.createNewFile()) {
35-
Util.getOutput().println("Optilog Note:Failed to create zip file!");
36-
return;
40+
if (!warn.isFile()) {
41+
if (!warn.createNewFile()) {
42+
Util.getOutput().println("Optilog Note:Failed to create zip file!");
43+
return;
44+
}
3745
}
38-
if (!debug.createNewFile()) {
39-
Util.getOutput().println("Optilog Note:Failed to create zip file!");
40-
return;
46+
if (!debug.isFile()) {
47+
if (!debug.createNewFile()) {
48+
Util.getOutput().println("Optilog Note:Failed to create zip file!");
49+
return;
50+
}
4151
}
42-
if (!fatal.createNewFile()) {
43-
Util.getOutput().println("Optilog Note:Failed to create zip file!");
44-
return;
52+
if (!fatal.isFile()) {
53+
if (!fatal.createNewFile()) {
54+
Util.getOutput().println("Optilog Note:Failed to create zip file!");
55+
return;
56+
}
4557
}
4658
} catch (IOException e) {
4759
Util.getOutput().println("Optilog Note:Failed to create zip file!");
4860
e.printStackTrace();
4961
return;
5062
}
51-
5263
try (ZipOutputStream output = new ZipOutputStream(new FileOutputStream(info))) {
53-
File[] file = new File(instance.info).listFiles();
64+
File[] file = new File(instance.info.substring(0, instance.info.length() - (instance.allSetting.fileName.length() + 1))).listFiles();
5465
if (file != null) {
5566
for (File f : file) {
5667
if (f.getName().endsWith(".log")) {
@@ -71,92 +82,100 @@ public static void zipAllLog(boolean delete, Optilog instance) {
7182
instance.error("Optilog Note:Failed to pack log file.", e);
7283
}
7384

74-
try (ZipOutputStream output = new ZipOutputStream(new FileOutputStream(error))) {
75-
File[] file = new File(instance.error).listFiles();
76-
if (file != null) {
77-
for (File f : file) {
78-
if (f.getName().endsWith(".log")) {
79-
output.putNextEntry(new ZipEntry(f.getName()));
80-
output.write(Files.readAllBytes(f.toPath()));
81-
output.closeEntry();
82-
if (delete) {
83-
if (!f.delete()) {
84-
instance.warn("Optilog Note:Delete #1 failed!", f.getName());
85+
if (!error.isFile()) {
86+
try (ZipOutputStream output = new ZipOutputStream(new FileOutputStream(error))) {
87+
File[] file = new File(instance.error.substring(0, instance.error.length() - (instance.allSetting.fileName.length() + 1))).listFiles();
88+
if (file != null) {
89+
for (File f : file) {
90+
if (f.getName().endsWith(".log")) {
91+
output.putNextEntry(new ZipEntry(f.getName()));
92+
output.write(Files.readAllBytes(f.toPath()));
93+
output.closeEntry();
94+
if (delete) {
95+
if (!f.delete()) {
96+
instance.warn("Optilog Note:Delete #1 failed!", f.getName());
97+
}
8598
}
8699
}
87100
}
101+
} else {
102+
instance.info("Optilog Note:No log file in error file path.");
88103
}
89-
} else {
90-
instance.info("Optilog Note:No log file in error file path.");
104+
} catch (IOException e) {
105+
instance.error("Optilog Note:Failed to pack log file.", e);
91106
}
92-
} catch (IOException e) {
93-
instance.error("Optilog Note:Failed to pack log file.", e);
94107
}
95108

96-
try (ZipOutputStream output = new ZipOutputStream(new FileOutputStream(warn))) {
97-
File[] file = new File(instance.warn).listFiles();
98-
if (file != null) {
99-
for (File f : file) {
100-
if (f.getName().endsWith(".log")) {
101-
output.putNextEntry(new ZipEntry(f.getName()));
102-
output.write(Files.readAllBytes(f.toPath()));
103-
output.closeEntry();
104-
if (delete) {
105-
if (!f.delete()) {
106-
instance.warn("Optilog Note:Delete #1 failed!", f.getName());
109+
if (!warn.isFile()) {
110+
try (ZipOutputStream output = new ZipOutputStream(new FileOutputStream(warn))) {
111+
File[] file = new File(instance.warn.substring(0, instance.warn.length() - (instance.allSetting.fileName.length() + 1))).listFiles();
112+
if (file != null) {
113+
for (File f : file) {
114+
if (f.getName().endsWith(".log")) {
115+
output.putNextEntry(new ZipEntry(f.getName()));
116+
output.write(Files.readAllBytes(f.toPath()));
117+
output.closeEntry();
118+
if (delete) {
119+
if (!f.delete()) {
120+
instance.warn("Optilog Note:Delete #1 failed!", f.getName());
121+
}
107122
}
108123
}
109124
}
125+
} else {
126+
instance.info("Optilog Note:No log file in warn file path.");
110127
}
111-
} else {
112-
instance.info("Optilog Note:No log file in warn file path.");
128+
} catch (IOException e) {
129+
instance.error("Optilog Note:Failed to pack log file.", e);
113130
}
114-
} catch (IOException e) {
115-
instance.error("Optilog Note:Failed to pack log file.", e);
116131
}
117132

118-
try (ZipOutputStream output = new ZipOutputStream(new FileOutputStream(debug))) {
119-
File[] file = new File(instance.debug).listFiles();
120-
if (file != null) {
121-
for (File f : file) {
122-
if (f.getName().endsWith(".log")) {
123-
output.putNextEntry(new ZipEntry(f.getName()));
124-
output.write(Files.readAllBytes(f.toPath()));
125-
output.closeEntry();
126-
if (delete) {
127-
if (!f.delete()) {
128-
instance.warn("Optilog Note:Delete #1 failed!", f.getName());
133+
if (!debug.isFile()) {
134+
try (ZipOutputStream output = new ZipOutputStream(new FileOutputStream(debug))) {
135+
File[] file = new File(instance.debug.substring(0, instance.debug.length() - (instance.allSetting.fileName.length() + 1))).listFiles();
136+
if (file != null) {
137+
for (File f : file) {
138+
if (f.getName().endsWith(".log")) {
139+
output.putNextEntry(new ZipEntry(f.getName()));
140+
output.write(Files.readAllBytes(f.toPath()));
141+
output.closeEntry();
142+
if (delete) {
143+
if (!f.delete()) {
144+
instance.warn("Optilog Note:Delete #1 failed!", f.getName());
145+
}
129146
}
130147
}
131148
}
149+
} else {
150+
instance.info("Optilog Note:No log file in debug file path.");
132151
}
133-
} else {
134-
instance.info("Optilog Note:No log file in debug file path.");
152+
} catch (IOException e) {
153+
instance.error("Optilog Note:Failed to pack log file.", e);
135154
}
136-
} catch (IOException e) {
137-
instance.error("Optilog Note:Failed to pack log file.", e);
138155
}
139156

140-
try (ZipOutputStream output = new ZipOutputStream(new FileOutputStream(fatal))) {
141-
File[] file = new File(instance.fatal).listFiles();
142-
if (file != null) {
143-
for (File f : file) {
144-
if (f.getName().endsWith(".log")) {
145-
output.putNextEntry(new ZipEntry(f.getName()));
146-
output.write(Files.readAllBytes(f.toPath()));
147-
output.closeEntry();
148-
if (delete) {
149-
if (!f.delete()) {
150-
instance.warn("Optilog Note:Delete #1 failed!", f.getName());
157+
if (!fatal.isFile()) {
158+
try (ZipOutputStream output = new ZipOutputStream(new FileOutputStream(fatal))) {
159+
File[] file = new File(instance.fatal.substring(0, instance.fatal.length() - (instance.allSetting.fileName.length() + 1))).listFiles();
160+
if (file != null) {
161+
for (File f : file) {
162+
if (f.getName().endsWith(".log")) {
163+
output.putNextEntry(new ZipEntry(f.getName()));
164+
output.write(Files.readAllBytes(f.toPath()));
165+
output.closeEntry();
166+
if (delete) {
167+
if (!f.delete()) {
168+
instance.warn("Optilog Note:Delete #1 failed!", f.getName());
169+
}
151170
}
152171
}
153172
}
173+
} else {
174+
instance.info("Optilog Note:No log file in fatal file path.");
154175
}
155-
} else {
156-
instance.info("Optilog Note:No log file in fatal file path.");
176+
} catch (IOException e) {
177+
instance.error("Optilog Note:Failed to pack log file.", e);
157178
}
158-
} catch (IOException e) {
159-
instance.error("Optilog Note:Failed to pack log file.", e);
160179
}
161180
}
162181
}

src/test/java/com/optilog/Test.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
package com.optilog;
22

3+
import com.optilog.log.Log;
4+
35
public class Test {
46
public static void main(String[] args) {
5-
7+
Log log = Log.initLog("%prop -cp /Settings.properties");
8+
log.info("dddd");
9+
log.command("%zip");
610
}
711
}

src/test/resources/Settings.properties

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,7 @@ printError=true
33
printWarn=true
44
printDebug=true
55
printFatal=true
6-
#defaultConsolePath=D:\\Program\\Feishu\\app\\assets\\object\\apps\\Intellij-IDEA\\Project\\Optilog-Client\\src\\test\\resources\\logs
7-
Path1=D:\\Program\\Feishu\\app\\assets\\object\\apps\\Intellij-IDEA\\Project\\Optilog-Client\\src\\test\\resources\\logs
8-
Path2=D:\\Program\\Feishu\\app\\assets\\object\\apps\\Intellij-IDEA\\Project\\Optilog-Client\\src\\test\\resources
9-
infoPath=%path1
10-
errorPath=%path2
11-
warnPath=%path1
12-
debugPath=%path1
13-
fatalPath=%path2
6+
defaultConsolePath=D:\\Program\\Feishu\\app\\assets\\object\\apps\\Intellij-IDEA\\Project\\Optilog-Client\\src\\test\\resources\\logs
147
consoleInfo=true
158
consoleDebug=true
169
consoleError=true
@@ -24,4 +17,4 @@ fatalSendToServer=true
2417
startClient=true
2518
socketNumber=65535
2619
packingFormat=[%yyyy-%MM-%dd|%HH:%mm:%ss(%SS))][%class %method(%file:%line)/%thread] %level:%msg
27-
fileName=Log.log
20+
fileName=%timeLog.log

src/test/resources/logs/2022-05-16 12-45-42Log(Client).log

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/test/resources/logs/2022-05-19 17-15-35Log(Client).log

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)