Skip to content

Commit a158164

Browse files
authored
Merge pull request #44 from Sandro642/feature/annot
Bump version to 0.3.4-STABLE and update Logger to control console out…
2 parents 5ffae2b + 8e76a67 commit a158164

5 files changed

Lines changed: 80 additions & 196 deletions

File tree

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ plugins {
55
}
66

77
group = 'fr.sandro642.github'
8-
version = '0.3.3-STABLE'
8+
version = '0.3.4-STABLE'
99

1010
tasks.register('printVersion') {
1111
doLast {

readme.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ And if you thought APIs were complicated, think again! With ConnectLib, it's lik
1717
---
1818

1919
```java
20-
Stable Version: 0.3.3-STABLE
20+
Stable Version: 0.3.4-STABLE
2121
```
2222

2323
---
@@ -58,6 +58,7 @@ Changelog:
5858
- [0.2.6.4-STABLE]: Added asynchronous job execution, allowing you to run tasks in the background without blocking your main application thread.
5959
- [0.2.7.2-STABLE]: Remove implementation Project Reactor
6060
- [0.2.9-STABLE]: Added support query variables in routes, allowing you to pass parameters directly in the URL.
61+
- [0.3.3-STABLE]: Minecraft Version 1.16 - Latest Version support + LangType 2.0 - Remove AnnotHandler, you can use logger.showLogs(); to display logs.
6162
```
6263

6364
---

src/main/java/fr/sandro642/github/annotations/AnnotHandler.java

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

src/main/java/fr/sandro642/github/misc/Logger.java

Lines changed: 72 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -5,63 +5,89 @@
55
* It provides methods to log messages with different severity levels:
66
* INFO, WARN, ERROR, and CRITICAL.
77
*
8+
* Use setShowLogs(true/false) to control console output.
9+
* Logs are always saved to file regardless of the setting.
10+
*
811
* @author Sandro642
912
* @version 1.0
1013
*/
1114

1215
public class Logger {
1316

14-
private Logs logs = new Logs();
17+
private Logs logs = new Logs();
18+
private static boolean showLogs = false; // Default: logs are hidden
19+
20+
/**
21+
* Enable console output for logs.
22+
* Call this method once to display all logs in console.
23+
* By default, logs are only saved to file without console output.
24+
* Logs are always saved to file regardless of this setting.
25+
*/
26+
public void showLogs() {
27+
showLogs = true;
28+
}
1529

16-
/**
17-
* Method to display an informational message in the console.
18-
* This method prints the message in green color and logs it.
19-
* @param msg
20-
*/
21-
public void INFO(String msg) {
22-
// Green
23-
String INFO = "\u001B[32m[INFO] \u001B[0m";
24-
System.out.println(INFO + msg);
30+
/**
31+
* Method to display an informational message in the console.
32+
* This method prints the message in green color if showLogs is enabled,
33+
* and always logs it to file.
34+
* @param msg The message to log
35+
*/
36+
public void INFO(String msg) {
37+
if (showLogs) {
38+
// Green
39+
String INFO = "\u001B[32m[INFO] \u001B[0m";
40+
System.out.println(INFO + msg);
41+
}
2542

26-
logs.MakeALog(msg, "INFO");
27-
}
43+
logs.MakeALog(msg, "INFO");
44+
}
2845

29-
/**
30-
* Method to display a warning message in the console.
31-
* This method prints the message in yellow color and logs it.
32-
* @param msg
33-
*/
34-
public void WARN(String msg) {
35-
// Yellow
36-
String WARN = "\u001B[33m[WARN] \u001B[0m";
37-
System.out.println(WARN + msg);
46+
/**
47+
* Method to display a warning message in the console.
48+
* This method prints the message in yellow color if showLogs is enabled,
49+
* and always logs it to file.
50+
* @param msg The message to log
51+
*/
52+
public void WARN(String msg) {
53+
if (showLogs) {
54+
// Yellow
55+
String WARN = "\u001B[33m[WARN] \u001B[0m";
56+
System.out.println(WARN + msg);
57+
}
3858

39-
logs.MakeALog(msg, "WARN");
40-
}
59+
logs.MakeALog(msg, "WARN");
60+
}
4161

42-
/**
43-
* Method to display an error message in the console.
44-
* This method prints the message in red color and logs it.
45-
* @param msg
46-
*/
47-
public void ERROR(String msg) {
48-
// Red
49-
String ERROR = "\u001B[31m[ERROR] \u001B[0m";
50-
System.out.println(ERROR + msg);
62+
/**
63+
* Method to display an error message in the console.
64+
* This method prints the message in red color if showLogs is enabled,
65+
* and always logs it to file.
66+
* @param msg The message to log
67+
*/
68+
public void ERROR(String msg) {
69+
if (showLogs) {
70+
// Red
71+
String ERROR = "\u001B[31m[ERROR] \u001B[0m";
72+
System.out.println(ERROR + msg);
73+
}
5174

52-
logs.MakeALog(msg, "ERROR");
53-
}
75+
logs.MakeALog(msg, "ERROR");
76+
}
5477

55-
/**
56-
* Method to display a critical message in the console.
57-
* This method prints the message in magenta color and logs it.
58-
* @param msg
59-
*/
60-
public void CRITICAL(String msg) {
61-
// Magenta
62-
String CRITICAL = "\u001B[35m[CRITICAL] \u001B[0m";
63-
System.out.println(CRITICAL + msg);
78+
/**
79+
* Method to display a critical message in the console.
80+
* This method prints the message in magenta color if showLogs is enabled,
81+
* and always logs it to file.
82+
* @param msg The message to log
83+
*/
84+
public void CRITICAL(String msg) {
85+
if (showLogs) {
86+
// Magenta
87+
String CRITICAL = "\u001B[35m[CRITICAL] \u001B[0m";
88+
System.out.println(CRITICAL + msg);
89+
}
6490

65-
logs.MakeALog(msg, "CRITICAL");
66-
}
67-
}
91+
logs.MakeALog(msg, "CRITICAL");
92+
}
93+
}

src/test/java/fr/sandro642/github/test/MainTest.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import fr.sandro642.github.enums.ResourceType;
99
import fr.sandro642.github.enums.VersionType;
1010
import fr.sandro642.github.misc.EnumLoader;
11+
import fr.sandro642.github.misc.Logger;
1112
import org.junit.jupiter.api.Test;
1213

1314
import java.util.Map;
@@ -49,12 +50,12 @@ public void initializeCAPI() {
4950

5051

5152
public static void main(String[] args) {
52-
connectLib.Init(ResourceType.TEST_RESOURCES, LangType.ENGLISH, TestRoutes.class);
53-
53+
connectLib.Init(ResourceType.TEST_RESOURCES, LangType.FRENCH, TestRoutes.class);
5454
try {
55+
connectLib.Logger().showLogs();
5556

5657
CompletableFuture<ApiFactory> apiFactoryCompletableFuture = connectLib.JobGetInfos()
57-
.getRoutes(VersionType.V1_BRANCH, MethodType.GET, TestRoutes.HELLO)
58+
.getRoutes( MethodType.GET, TestRoutes.HELLO)
5859
.getResponse();
5960

6061
ApiFactory response = apiFactoryCompletableFuture.get(5, TimeUnit.SECONDS);
@@ -67,6 +68,7 @@ public static void main(String[] args) {
6768
}
6869
}
6970

71+
7072
@Test
7173
public void testUseFullRoute() {
7274
connectLib.Init(ResourceType.TEST_RESOURCES, LangType.FRENCH, TestRoutes.class);

0 commit comments

Comments
 (0)