Skip to content
This repository was archived by the owner on Aug 6, 2024. It is now read-only.

Commit b87a9f4

Browse files
committed
debug mode
1 parent 44dc85c commit b87a9f4

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

src/main/java/ir/xenoncommunity/MainRunner.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
@Getter
1111
public class MainRunner {
12+
public boolean isDebug;
1213
public final CommandLineParser parser;
1314
public final TaskManager taskManager;
1415
public final SocketUtils socketUtils;
@@ -21,19 +22,29 @@ public MainRunner(CommandLineParser parser) {
2122
}
2223

2324
public void run() {
24-
getLogger().print(Logger.LEVEL.INFO,"", "test");
25+
this.isDebug = Main.runner.parser.get("--debug", Boolean.class);
2526
val ip = Main.runner.parser.get("--ip", String.class);
2627
val port = Main.runner.parser.get("--port", Integer.class);
2728
val maxThreads = Main.runner.parser.get("--threads", Integer.class);
2829
val isResult = Main.runner.parser.get("--sendResult", Boolean.class);
2930
val isKeepAlive = Main.runner.parser.get("--keepAlive", Boolean.class);
31+
if(this.isDebug()){
32+
getLogger().setSection("DEBUG");
33+
getLogger().print(Logger.LEVEL.INFO, "ip is: " + ip);
34+
getLogger().print(Logger.LEVEL.INFO, "port is: " + port);
35+
getLogger().print(Logger.LEVEL.INFO, "maxThreads is: " + maxThreads);
36+
getLogger().print(Logger.LEVEL.INFO, "isResult is: " + isResult);
37+
getLogger().print(Logger.LEVEL.INFO, "isKeepAlive is: " + isKeepAlive);
38+
}
3039
for(int i = 0; i <= maxThreads; i++){
40+
if(this.isDebug)
41+
getLogger().print(Logger.LEVEL.INFO, "adding new thread. max: " + maxThreads);
3142
getTaskManager().add(new Thread(() -> {
32-
while (true) {
43+
while (true)
3344
socketUtils.connect(ip, port, isResult, isKeepAlive);
34-
}
3545
}));
3646
}
47+
getLogger().print(Logger.LEVEL.INFO, "doing tasks...");
3748
getTaskManager().doTasks();
3849
}
3950
}

src/main/java/ir/xenoncommunity/utils/Logger.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
package ir.xenoncommunity.utils;
22

3+
import lombok.Setter;
34
import lombok.val;
45

56
public class Logger {
67
public String osName = System.getProperty("os.name");
78
public String osVersion = System.getProperty("os.version");
89
private boolean sendOsName;
910
private boolean sendOsVersion;
11+
@Setter
12+
public String section = "NONE";
1013
public Logger(final boolean sendOsName, final boolean sendOSVersion){
1114
this.sendOsName = sendOsName;
1215
this.sendOsVersion = sendOSVersion;
1316
}
14-
public void print(final LEVEL levelIn, final String sectionIn, final String message){
17+
public void print(final LEVEL levelIn, final String message){
1518
val osName = sendOsName ? this.osName : "";
1619
val osVersion = sendOsVersion ? this.osVersion : "";
17-
val section = sectionIn.equals("") ? "NONE" : sectionIn;
18-
System.out.println(String.format("[%s-%s] [%s] [%s]>> %s", osName, osVersion, levelIn, section, message));
20+
System.out.println(String.format("[%s-%s] [%s] [%s]>> %s", osName, osVersion, levelIn, this.section, message));
1921

2022
}
2123

src/main/java/ir/xenoncommunity/utils/SocketUtils.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ public class SocketUtils {
99
@SneakyThrows
1010
public void connect(final String ipIn, final int port, final boolean sendResult, final boolean keepAlive){
1111
try(val socket = new Socket(ipIn, port)){
12+
Main.runner.getLogger().setSection("CONNECT");
1213
if (sendResult && socket.isConnected()) {
13-
System.out.printf("Connected! ip: %s, port: %s, threads: %s\n", ipIn, port, Main.runner.getTaskManager().tasks.size());
14+
Main.runner.getLogger().print(Logger.LEVEL. INFO, String.format("Connected! ip: %s, port: %s, threads: %s\n", ipIn, port, Main.runner.getTaskManager().tasks.size()));
1415
}
1516
if (keepAlive) {
1617
socket.setKeepAlive(true);

0 commit comments

Comments
 (0)