Skip to content

Commit 70927d2

Browse files
authored
Merge pull request #42 from Sandro642/feature/lang
Update logging messages to use LangManager for better localization su…
2 parents 80be83b + 5376291 commit 70927d2

12 files changed

Lines changed: 145 additions & 73 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.1-STABLE'
8+
version = '0.3.2-STABLE'
99

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

readme.md

Lines changed: 4 additions & 4 deletions
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.1-STABLE
20+
Stable Version: 0.3.2-STABLE
2121
```
2222

2323
---
@@ -34,8 +34,8 @@ Hook -----------------------|
3434
---
3535
## LangManager
3636
```
37-
EN : Released - Version 0.1.1
38-
FR : Sorti - Version 0.1.0
37+
EN : Released - Version 1.2
38+
FR : Sorti - Version 1.1
3939
```
4040

4141
---
@@ -115,7 +115,7 @@ repositories {
115115

116116
dependencies {
117117

118-
implementation("fr.sandro642.github:ConnectLib:0.3.1-STABLE")
118+
implementation("fr.sandro642.github:ConnectLib:0.3.2-STABLE")
119119

120120
}
121121

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package fr.sandro642.github.annotations;
22

33
import fr.sandro642.github.ConnectLib;
4+
import fr.sandro642.github.enums.lang.CategoriesType;
45

56
import java.lang.annotation.ElementType;
67
import java.lang.annotation.Retention;
@@ -13,6 +14,7 @@
1314
import java.io.File;
1415
import java.net.URL;
1516
import java.util.ArrayList;
17+
import java.util.Map;
1618

1719
/**
1820
* AnnotHandler is a class that manages the discovery and execution of listeners annotated with @AnnotConnect.
@@ -66,7 +68,7 @@ private void discoverListeners() {
6668
}
6769
}
6870
} catch (Exception e) {
69-
throw new RuntimeException("Error during listener discovery", e);
71+
ConnectLib.Logger().ERROR(ConnectLib.LangManager().getMessage(CategoriesType.ANNOTATION_PACKAGE, "discoverlistener.error"));
7072
}
7173
}
7274

@@ -99,7 +101,7 @@ private List<Class<?>> getClassesInPackage(String packageName) {
99101
}
100102
}
101103
} catch (Exception e) {
102-
ConnectLib.Logger().WARN("Failed to retrieve classes in package: " + packageName + ". Exception: " + e.getMessage());
104+
ConnectLib.Logger().WARN(ConnectLib.LangManager().getMessage(CategoriesType.ANNOTATION_PACKAGE, "getclassesinpackage.error", Map.of("package", packageName, "exception", e.getMessage())));
103105
}
104106
return classes;
105107
}

src/main/java/fr/sandro642/github/api/ApiClient.java

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package fr.sandro642.github.api;
22

33
import fr.sandro642.github.ConnectLib;
4+
import fr.sandro642.github.enums.lang.CategoriesType;
45
import fr.sandro642.github.misc.Logger;
56
import org.springframework.web.reactive.function.client.WebClient;
67
import reactor.core.publisher.Mono;
@@ -54,7 +55,7 @@ public ApiClient() {
5455
String baseUrl = (String) ConnectLib.StoreAndRetrieve().store.get(ConnectLib.StoreAndRetrieve().URL_KEY);
5556

5657
if (baseUrl == null) {
57-
logger.CRITICAL("Base URL not found in configuration. Please set the base URL in the configuration file.");
58+
logger.CRITICAL(ConnectLib.LangManager().getMessage(CategoriesType.APICLIENT_CLASS, "construct.urlbase"));
5859
}
5960

6061
this.webClient = WebClient.builder()
@@ -68,20 +69,20 @@ public ApiClient() {
6869
* @return a Mono that emits the ApiFactory response containing the parsed JSON data.
6970
*/
7071
public Mono<ApiFactory> callAPIGet(String routeName) {
71-
logger.INFO("Call GET to : " + routeName);
72+
logger.INFO(ConnectLib.LangManager().getMessage(CategoriesType.APICLIENT_CLASS, "call.get", Map.of("routename", routeName)));
7273
return webClient.get()
7374
.uri(routeName)
7475
.retrieve()
7576
.bodyToMono(String.class)
7677
.subscribeOn(Schedulers.boundedElastic())
7778
.doOnNext(thread ->
78-
ConnectLib.Logger().INFO("Current thread in use: " + Thread.currentThread().getName()))
79+
ConnectLib.Logger().INFO(ConnectLib.LangManager().getMessage(CategoriesType.APICLIENT_CLASS, "call.threadinuse", "thread", Thread.currentThread().getName())))
7980
.map(rawJson -> {
8081
response.parseFromRawJson(rawJson);
8182
return response;
8283
})
8384
.doOnNext(lastResponse::set)
84-
.doOnError(error -> logger.CRITICAL("Error while call GET: " + error.getMessage()));
85+
.doOnError(error -> logger.CRITICAL(ConnectLib.LangManager().getMessage(CategoriesType.APICLIENT_CLASS, "general.error", Map.of("method", "GET", "exception", error.getMessage()))));
8586
}
8687

8788
/**
@@ -91,21 +92,21 @@ public Mono<ApiFactory> callAPIGet(String routeName) {
9192
* @return a Mono that emits the ApiFactory response containing the parsed JSON data.
9293
*/
9394
public Mono<ApiFactory> callAPIPost(String routeName, Map<String, Object> body) {
94-
logger.INFO("Call POST to : " + routeName);
95+
logger.INFO(ConnectLib.LangManager().getMessage(CategoriesType.APICLIENT_CLASS, "call.post", Map.of("routename", routeName)));
9596
return webClient.post()
9697
.uri(routeName)
9798
.bodyValue(body != null ? body : Map.of())
9899
.retrieve()
99100
.bodyToMono(String.class)
100101
.subscribeOn(Schedulers.boundedElastic())
101102
.doOnNext(thread ->
102-
ConnectLib.Logger().INFO("Thread en cours d'utilisation: " + Thread.currentThread().getName()))
103+
ConnectLib.Logger().INFO(ConnectLib.LangManager().getMessage(CategoriesType.APICLIENT_CLASS, "call.threadinuse", "thread", Thread.currentThread().getName())))
103104
.map(rawJson -> {
104105
response.parseFromRawJson(rawJson);
105106
return response;
106107
})
107108
.doOnNext(lastResponse::set)
108-
.doOnError(error -> logger.CRITICAL("Error while call POST: " + error.getMessage()));
109+
.doOnError(error -> logger.CRITICAL(ConnectLib.LangManager().getMessage(CategoriesType.APICLIENT_CLASS, "general.error", Map.of("method", "POST", "exception", error.getMessage()))));
109110
}
110111

111112
/**
@@ -115,21 +116,21 @@ public Mono<ApiFactory> callAPIPost(String routeName, Map<String, Object> body)
115116
* @return a Mono that emits the ApiFactory response containing the parsed JSON data.
116117
*/
117118
public Mono<ApiFactory> callAPIPut(String routeName, Map<String, Object> body) {
118-
logger.INFO("Call PUT to : " + routeName);
119+
logger.INFO(ConnectLib.LangManager().getMessage(CategoriesType.APICLIENT_CLASS, "call.put", Map.of("routename", routeName)));
119120
return webClient.put()
120121
.uri(routeName)
121122
.bodyValue(body != null ? body : Map.of())
122123
.retrieve()
123124
.bodyToMono(String.class)
124125
.subscribeOn(Schedulers.boundedElastic())
125126
.doOnNext(thread ->
126-
ConnectLib.Logger().INFO("Thread en cours d'utilisation: " + Thread.currentThread().getName()))
127+
ConnectLib.Logger().INFO(ConnectLib.LangManager().getMessage(CategoriesType.APICLIENT_CLASS, "call.threadinuse", "thread", Thread.currentThread().getName())))
127128
.map(rawJson -> {
128129
response.parseFromRawJson(rawJson);
129130
return response;
130131
})
131132
.doOnNext(lastResponse::set)
132-
.doOnError(error -> logger.CRITICAL("Error while call PUT: " + error.getMessage()));
133+
.doOnError(error -> logger.CRITICAL(ConnectLib.LangManager().getMessage(CategoriesType.APICLIENT_CLASS, "general.error", Map.of("method", "PUT", "exception", error.getMessage()))));
133134
}
134135

135136
/**
@@ -139,21 +140,21 @@ public Mono<ApiFactory> callAPIPut(String routeName, Map<String, Object> body) {
139140
* @return a Mono that emits the ApiFactory response containing the parsed JSON data.
140141
*/
141142
public Mono<ApiFactory> callAPIPatch(String routeName, Map<String, Object> body) {
142-
logger.INFO("Call PATCH to : " + routeName);
143+
logger.INFO(ConnectLib.LangManager().getMessage(CategoriesType.APICLIENT_CLASS, "call.patch", Map.of("routename", routeName)));
143144
return webClient.patch()
144145
.uri(routeName)
145146
.bodyValue(body != null ? body : Map.of())
146147
.retrieve()
147148
.bodyToMono(String.class)
148149
.subscribeOn(Schedulers.boundedElastic())
149150
.doOnNext(thread ->
150-
ConnectLib.Logger().INFO("Thread en cours d'utilisation: " + Thread.currentThread().getName()))
151+
ConnectLib.Logger().INFO(ConnectLib.LangManager().getMessage(CategoriesType.APICLIENT_CLASS, "call.threadinuse", "thread", Thread.currentThread().getName())))
151152
.map(rawJson -> {
152153
response.parseFromRawJson(rawJson);
153154
return response;
154155
})
155156
.doOnNext(lastResponse::set)
156-
.doOnError(error -> logger.CRITICAL("Error while call PATCH: " + error.getMessage()));
157+
.doOnError(error -> logger.CRITICAL(ConnectLib.LangManager().getMessage(CategoriesType.APICLIENT_CLASS, "general.error", Map.of("method", "PATCH", "exception", error.getMessage()))));
157158
}
158159

159160
/**
@@ -162,19 +163,19 @@ public Mono<ApiFactory> callAPIPatch(String routeName, Map<String, Object> body)
162163
* @return a Mono that emits the ApiFactory response containing the parsed JSON data.
163164
*/
164165
public Mono<ApiFactory> callAPIDelete(String routeName) {
165-
logger.INFO("Call DELETE to : " + routeName);
166+
logger.INFO(ConnectLib.LangManager().getMessage(CategoriesType.APICLIENT_CLASS, "call.delete", Map.of("routename", routeName)));
166167
return webClient.delete()
167168
.uri(routeName)
168169
.retrieve()
169170
.bodyToMono(String.class)
170171
.subscribeOn(Schedulers.boundedElastic())
171172
.doOnNext(thread ->
172-
ConnectLib.Logger().INFO("Thread en cours d'utilisation: " + Thread.currentThread().getName()))
173+
ConnectLib.Logger().INFO(ConnectLib.LangManager().getMessage(CategoriesType.APICLIENT_CLASS, "call.threadinuse", "thread", Thread.currentThread().getName())))
173174
.map(rawJson -> {
174175
response.parseFromRawJson(rawJson);
175176
return response;
176177
})
177178
.doOnNext(lastResponse::set)
178-
.doOnError(error -> logger.CRITICAL("Error while call DELETE: " + error.getMessage()));
179+
.doOnError(error -> logger.CRITICAL(ConnectLib.LangManager().getMessage(CategoriesType.APICLIENT_CLASS, "general.error", Map.of("method", "DELETE", "exception", error.getMessage()))));
179180
}
180181
}

src/main/java/fr/sandro642/github/api/ApiFactory.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.fasterxml.jackson.core.type.TypeReference;
44
import com.fasterxml.jackson.databind.ObjectMapper;
55
import fr.sandro642.github.ConnectLib;
6+
import fr.sandro642.github.enums.lang.CategoriesType;
67

78
import java.util.Map;
89

@@ -29,7 +30,7 @@ protected void parseFromRawJson(String rawJson) {
2930
ObjectMapper mapper = new ObjectMapper();
3031
this.rawData = mapper.readValue(rawJson, new TypeReference<Map<String, Object>>() {});
3132
} catch (Exception e) {
32-
throw new RuntimeException("Erreur while parsing " + e.getMessage(), e);
33+
ConnectLib.Logger().ERROR(ConnectLib.LangManager().getMessage(CategoriesType.APIFACTORY_CLASS, "parsefromrawjson.error", Map.of("json", rawJson, "exception", e.getMessage())));
3334
}
3435
}
3536

@@ -43,13 +44,13 @@ protected void parseFromRawJson(String rawJson) {
4344
public <O> Object getData(O type) {
4445
try {
4546
if (rawData == null) {
46-
ConnectLib.Logger().ERROR("Data has not been initialized. Please call parseFromRawJson() first.");
47+
ConnectLib.Logger().ERROR(ConnectLib.LangManager().getMessage(CategoriesType.APIFACTORY_CLASS, "general.mustbe"));
4748
return null;
4849
}
4950

5051
return rawData.get(type.toString().toLowerCase());
5152
} catch (Exception e) {
52-
ConnectLib.Logger().ERROR("Unable to retrieve data for type: " + type + ". " + e.getMessage());
53+
ConnectLib.Logger().ERROR(ConnectLib.LangManager().getMessage(CategoriesType.APIFACTORY_CLASS, "getdata.error", Map.of("type", type.toString(), "exception", e.getMessage())));
5354
}
5455
return null;
5556
}
@@ -65,7 +66,7 @@ public <O> Object getData(O type) {
6566
public <O, K> Object getSpecData(O type, K value) {
6667
try {
6768
if (rawData == null) {
68-
ConnectLib.Logger().ERROR("Data has not been initialized. Please call parseFromRawJson() first.");
69+
ConnectLib.Logger().ERROR(ConnectLib.LangManager().getMessage(CategoriesType.APIFACTORY_CLASS, "general.mustbe"));
6970
return null;
7071
}
7172

@@ -75,7 +76,7 @@ public <O, K> Object getSpecData(O type, K value) {
7576
return nestedMap.get(value.toString().toLowerCase());
7677
}
7778
} catch (Exception e) {
78-
ConnectLib.Logger().ERROR("Unable to retrieve specific data for type: " + type + " and value: " + value + ". " + e.getMessage());
79+
ConnectLib.Logger().ERROR(ConnectLib.LangManager().getMessage(CategoriesType.APIFACTORY_CLASS, "getspecdata.error", Map.of("type", type.toString(), "value", value.toString(), "exception", e.getMessage())));
7980
}
8081
return null;
8182
}
@@ -89,12 +90,12 @@ public <O, K> Object getSpecData(O type, K value) {
8990
public Object display() {
9091
try {
9192
if (rawData == null) {
92-
ConnectLib.Logger().ERROR("Data has not been initialized. Please call parseFromRawJson() first.");
93+
ConnectLib.Logger().ERROR(ConnectLib.LangManager().getMessage(CategoriesType.APIFACTORY_CLASS, "general.mustbe"));
9394
return null;
9495
}
9596
return rawData;
9697
} catch (Exception e) {
97-
ConnectLib.Logger().ERROR("Unable to display data: " + e.getMessage());
98+
ConnectLib.Logger().ERROR(ConnectLib.LangManager().getMessage(CategoriesType.APIFACTORY_CLASS, "display.error", "exception", e.getMessage()));
9899
}
99100
return null;
100101
}

src/main/java/fr/sandro642/github/enums/lang/CategoriesType.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,13 @@ public enum CategoriesType {
1414
*/
1515
CONNECTLIB_CLASS("connectlib.class"),
1616
ANNOTATION_PACKAGE("annotation.package"),
17-
YAMLUTILS_CLASS("yamlutils.class")
17+
YAMLUTILS_CLASS("yamlutils.class"),
18+
JOBS_PACKAGE("jobs.package"),
19+
MCSUPPORT_CLASS("mcsupport.class"),
20+
LANGSUPPORT_CLASS("langsupport.class"),
21+
HOOKMANAGER_CLASS("hookmanager.class"),
22+
APIFACTORY_CLASS("apifactory.class"),
23+
APICLIENT_CLASS("apiclient.class"),
1824
;
1925

2026
/**

src/main/java/fr/sandro642/github/hook/HookManager.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import fr.sandro642.github.ConnectLib;
44
import fr.sandro642.github.enums.ResourceType;
5+
import fr.sandro642.github.enums.lang.CategoriesType;
56
import fr.sandro642.github.misc.Logger;
67

78
/**
@@ -21,12 +22,6 @@ public class HookManager {
2122
*/
2223
private static HookManager instance;
2324

24-
/**
25-
* Logger instance for logging messages.
26-
* This logger is used to log errors and other messages related to the hook management.
27-
*/
28-
private static Logger logger = new Logger();
29-
3025
/**
3126
* Initializes the HookManager with the specified resource type.
3227
*
@@ -62,7 +57,7 @@ public void FILE_LOCATION_KEY() {
6257

6358

6459
default:
65-
logger.CRITICAL("Unsupported resource type: " + resourceType);
60+
ConnectLib.Logger().CRITICAL(ConnectLib.LangManager().getMessage(CategoriesType.HOOKMANAGER_CLASS, "general.unsupportedtype", "type", resourceType.toString()));
6661
}
6762
}
6863

@@ -76,8 +71,9 @@ public String BASE_PATH() {
7671

7772

7873
default:
79-
logger.CRITICAL("Unsupported resource type: " + resourceType);
80-
throw new IllegalArgumentException("Unsupported resource type: " + resourceType);
74+
String message = ConnectLib.LangManager().getMessage(CategoriesType.HOOKMANAGER_CLASS, "general.unsupportedtype", "type", resourceType.toString());
75+
ConnectLib.Logger().CRITICAL(message);
76+
throw new IllegalArgumentException(message);
8177
}
8278
}
8379

src/main/java/fr/sandro642/github/hook/LangSupport.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package fr.sandro642.github.hook;
22

3+
import fr.sandro642.github.ConnectLib;
34
import fr.sandro642.github.enums.MethodType;
5+
import fr.sandro642.github.enums.lang.CategoriesType;
46

57
/**
68
* LangSupport is a placeholder class for future language support implementations.
@@ -17,11 +19,6 @@ public class LangSupport {
1719
*/
1820
private static LangSupport instance;
1921

20-
/**
21-
* Prefix for language files.
22-
*/
23-
private final String PREFIX = "lang/";
24-
2522
/**
2623
* Private singleton langType.
2724
* @return langTypeSingleton
@@ -35,7 +32,8 @@ public class LangSupport {
3532
*/
3633
public MethodType.LangType setLangTypeVariable(MethodType.LangType langType) {
3734
if (langType == null) {
38-
throw new IllegalArgumentException("LangType cannot be null");
35+
ConnectLib.Logger().ERROR(ConnectLib.LangManager().getMessage(CategoriesType.LANGSUPPORT_CLASS, "general.illegalarg"));
36+
3937
}
4038
this.langTypeSingleton = langType;
4139
return this.langTypeSingleton;
@@ -48,10 +46,10 @@ public MethodType.LangType setLangTypeVariable(MethodType.LangType langType) {
4846
*/
4947
public String getPathFile() {
5048
if (langTypeSingleton == null) {
51-
throw new IllegalArgumentException("LangType cannot be null");
49+
ConnectLib.Logger().ERROR(ConnectLib.LangManager().getMessage(CategoriesType.LANGSUPPORT_CLASS, "general.illegalarg"));
5250
}
5351

54-
return PREFIX + langTypeSingleton.getLang() + ".lang";
52+
return "lang/" + langTypeSingleton.getLang() + ".lang";
5553
}
5654

5755
/**

0 commit comments

Comments
 (0)