Skip to content

Commit d7dbec2

Browse files
committed
[优化] 命令行输出优化 @4ra1n
1 parent ce10e78 commit d7dbec2

4 files changed

Lines changed: 36 additions & 33 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
更新日志:
44

55
- [BUG] 删除无效命令行参数 @4ra1n
6+
- [优化] 命令行输出优化 @4ra1n
67
- [文档] 提供 `DATABASE.md``AI` 解释数据库结构 @4ra1n
78

89
## 1.0.0

src/main/java/me/n1ar4/jar/analyzer/analyze/spring/SpringService.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,17 @@ public static void start(Set<ClassFileEntity> classFileList,
4848
e.printStackTrace(ps);
4949
ps.flush();
5050
ps.close();
51-
System.out.println("#################### SPRING ANALYZE ERROR ####################");
52-
System.out.print(bao);
51+
logger.error("#################### SPRING ANALYZE ERROR ####################");
52+
logger.error("{}", bao);
5353
}
5454
} catch (Exception e) {
5555
ByteArrayOutputStream bao = new ByteArrayOutputStream();
5656
PrintWriter ps = new PrintWriter(bao);
5757
e.printStackTrace(ps);
5858
ps.flush();
5959
ps.close();
60-
System.out.println("#################### SPRING ANALYZE ERROR ####################");
61-
System.out.print(bao);
60+
logger.error("#################### SPRING ANALYZE ERROR ####################");
61+
logger.error("{}", bao);
6262
}
6363
}
6464
}

src/main/java/me/n1ar4/jar/analyzer/engine/EngineMain.java

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,8 @@ public class EngineMain {
2424

2525
@SuppressWarnings("all")
2626
public static void main(String[] args) {
27-
System.out.println("=== Jar Analyzer Engine " + EngineConst.version + " ===");
28-
System.out.println("Build SQLite database from JAR/WAR files");
29-
System.out.println();
27+
logger.info("=== Jar Analyzer Engine {} ===", EngineConst.version);
28+
logger.info("Build SQLite database from JAR/WAR files");
3029

3130
EngineBuildCmd cmd = new EngineBuildCmd();
3231
JCommander jc = JCommander.newBuilder()
@@ -37,7 +36,7 @@ public static void main(String[] args) {
3736
try {
3837
jc.parse(args);
3938
} catch (Exception e) {
40-
System.err.println("Error: " + e.getMessage());
39+
logger.error("Error: {}", e.getMessage());
4140
jc.usage();
4241
System.exit(1);
4342
return;
@@ -49,15 +48,15 @@ public static void main(String[] args) {
4948
}
5049

5150
if (cmd.jarPath == null || cmd.jarPath.isEmpty()) {
52-
System.err.println("Error: --jar parameter is required");
51+
logger.error("Error: --jar parameter is required");
5352
jc.usage();
5453
System.exit(1);
5554
return;
5655
}
5756

5857
Path jarPath = Paths.get(cmd.jarPath);
5958
if (!Files.exists(jarPath)) {
60-
System.err.println("Error: JAR path does not exist: " + cmd.jarPath);
59+
logger.error("Error: JAR path does not exist: {}", cmd.jarPath);
6160
System.exit(1);
6261
return;
6362
}
@@ -76,7 +75,7 @@ public static void main(String[] args) {
7675
if (Files.exists(rtPath)) {
7776
config.setRtJarPath(rtPath);
7877
} else {
79-
System.err.println("Warning: rt.jar path does not exist: " + cmd.rtJarPath);
78+
logger.warn("rt.jar path does not exist: {}", cmd.rtJarPath);
8079
}
8180
}
8281

@@ -86,7 +85,7 @@ public static void main(String[] args) {
8685
config.setClassBlackList(new String(Files.readAllBytes(
8786
Paths.get(cmd.classBlackListFile))));
8887
} catch (IOException e) {
89-
System.err.println("Warning: cannot read black list file: " + cmd.classBlackListFile);
88+
logger.warn("cannot read black list file: {}", cmd.classBlackListFile);
9089
}
9190
} else if (cmd.classBlackList != null) {
9291
config.setClassBlackList(cmd.classBlackList);
@@ -98,24 +97,23 @@ public static void main(String[] args) {
9897
config.setClassWhiteList(new String(Files.readAllBytes(
9998
Paths.get(cmd.classWhiteListFile))));
10099
} catch (IOException e) {
101-
System.err.println("Warning: cannot read white list file: " + cmd.classWhiteListFile);
100+
logger.warn("cannot read white list file: {}", cmd.classWhiteListFile);
102101
}
103102
} else if (cmd.classWhiteList != null) {
104103
config.setClassWhiteList(cmd.classWhiteList);
105104
}
106105

107106
// Print config summary
108-
System.out.println("Configuration:");
109-
System.out.println(" JAR Path: " + config.getJarPath());
110-
System.out.println(" DB Path: jar-analyzer.db");
111-
System.out.println(" Temp Dir: " + EngineConst.tempDir);
112-
System.out.println(" Quick Mode: " + config.isQuickMode());
113-
System.out.println(" Fix Class: " + config.isFixClass());
114-
System.out.println(" Inner JARs: " + config.isJarsInJar());
115-
System.out.println(" Fix Impl: " + config.isFixMethodImpl());
116-
System.out.println(" Black List: " + (config.getClassBlackList() != null ? "set" : "none"));
117-
System.out.println(" White List: " + (config.getClassWhiteList() != null ? "set" : "none"));
118-
System.out.println();
107+
logger.info("Configuration:");
108+
logger.info(" JAR Path: {}", config.getJarPath());
109+
logger.info(" DB Path: jar-analyzer.db");
110+
logger.info(" Temp Dir: {}", EngineConst.tempDir);
111+
logger.info(" Quick Mode: {}", config.isQuickMode());
112+
logger.info(" Fix Class: {}", config.isFixClass());
113+
logger.info(" Inner JARs: {}", config.isJarsInJar());
114+
logger.info(" Fix Impl: {}", config.isFixMethodImpl());
115+
logger.info(" Black List: {}", config.getClassBlackList() != null ? "set" : "none");
116+
logger.info(" White List: {}", config.getClassWhiteList() != null ? "set" : "none");
119117

120118
long startTime = System.currentTimeMillis();
121119

@@ -129,9 +127,8 @@ public static void main(String[] args) {
129127
}
130128

131129
long elapsed = System.currentTimeMillis() - startTime;
132-
System.out.println();
133-
System.out.println("=== Build Complete ===");
134-
System.out.printf("Time elapsed: %.2f seconds%n", elapsed / 1000.0);
135-
System.out.println("Database: jar-analyzer.db");
130+
logger.info("=== Build Complete ===");
131+
logger.info("Time elapsed: {} seconds", String.format("%.2f", elapsed / 1000.0));
132+
logger.info("Database: jar-analyzer.db");
136133
}
137134
}

src/main/java/me/n1ar4/jar/analyzer/engine/ProgressCallback.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010

1111
package me.n1ar4.jar.analyzer.engine;
1212

13+
import me.n1ar4.jar.analyzer.engine.log.LogManager;
14+
import me.n1ar4.jar.analyzer.engine.log.Logger;
15+
1316
/**
1417
* 引擎构建进度回调
1518
* GUI 模式下可用于更新进度条和日志面板
@@ -47,29 +50,31 @@ public interface ProgressCallback {
4750
* 默认的控制台回调(CLI 模式使用)
4851
*/
4952
ProgressCallback CONSOLE = new ProgressCallback() {
53+
private final Logger logger = LogManager.getLogger();
54+
5055
@Override
5156
public void onProgress(int percent) {
52-
System.out.printf("[ENGINE] Progress: %d%%\n", percent);
57+
logger.info("[ENGINE] Progress: {}%", percent);
5358
}
5459

5560
@Override
5661
public void onInfo(String message) {
57-
System.out.printf("[ENGINE] INFO: %s\n", message);
62+
logger.info("[ENGINE] INFO: {}", message);
5863
}
5964

6065
@Override
6166
public void onWarn(String message) {
62-
System.out.printf("[ENGINE] WARN: %s\n", message);
67+
logger.warn("[ENGINE] WARN: {}", message);
6368
}
6469

6570
@Override
6671
public void onError(String message) {
67-
System.err.printf("[ENGINE] ERROR: %s\n", message);
72+
logger.error("[ENGINE] ERROR: {}", message);
6873
}
6974

7075
@Override
7176
public void onStats(String key, String value) {
72-
System.out.printf("[ENGINE] %s: %s\n", key, value);
77+
logger.info("[ENGINE] {}: {}", key, value);
7378
}
7479
};
7580
}

0 commit comments

Comments
 (0)