Skip to content

Commit 05c91e6

Browse files
committed
Use slf4j logging facade.
1 parent 8c2c52d commit 05c91e6

File tree

4 files changed

+17
-11
lines changed

4 files changed

+17
-11
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
.idea/
33
**/build
44
.out/
5-
**/books.jsonl
5+
**/books.jsonl
6+
config.json

CONTRIBUTING.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ Before making a PR to this repository look out for the following guidelines.
2222
```
2323
- Run the following command:
2424
```bash
25-
java -jar swagger-codegen-cli-3.0.20.jar generate -i <path-to-spec> -l jaxrs-cxf-client -c <path-to-config.json> -o <out-dir>
25+
java --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.net=ALL-UNNAMED \
26+
--add-opens java.base/java.lang.reflect=ALL-UNNAMED --add-opens java.base/java.text=ALL-UNNAMED \
27+
--add-opens java.desktop/java.awt.font=ALL-UNNAMED -jar ~/apps/swagger-codegen-cli-3.0.20.jar generate \
28+
-i /path/to/typesense-api-spec/openapi.yml -l jaxrs-cxf-client -c config.json -o /tmp/model
2629
```
2730
- Now, copy the content under ```<out-dir>/src/gen/java/org/typesense/model``` and replace it with the content of the ```typesense-java/src/main/java/org/typesense/model``` folder in the `typesense-java` client repository.
2831
- And then make the necessary changes in `api` folder.

build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,10 @@ dependencies {
6060
implementation "javax.xml.bind:jaxb-api:2.3.1"
6161
implementation "com.fasterxml.jackson.core:jackson-databind:2.14.1"
6262
implementation "io.swagger.core.v3:swagger-annotations:2.0.0"
63-
implementation "org.apache.logging.log4j:log4j-core:2.19.0"
63+
implementation "org.slf4j:slf4j-api:2.0.5"
6464
implementation "com.squareup.okhttp3:okhttp:4.9.1"
6565

66+
testImplementation "org.slf4j:slf4j-simple:2.0.5"
6667
testImplementation "junit:junit:4.12"
6768
testImplementation "org.hamcrest:hamcrest-all:1.3"
6869
integrationTestImplementation "junit:junit:4.12"

src/main/java/org/typesense/api/ApiCall.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
import com.fasterxml.jackson.databind.DeserializationFeature;
55
import com.fasterxml.jackson.databind.ObjectMapper;
66
import okhttp3.*;
7-
import org.apache.logging.log4j.LogManager;
8-
import org.apache.logging.log4j.Logger;
7+
import org.slf4j.Logger;
8+
import org.slf4j.LoggerFactory;
99
import org.typesense.api.exceptions.*;
1010
import org.typesense.model.ErrorResponse;
1111
import org.typesense.resources.Node;
@@ -30,7 +30,7 @@ public class ApiCall {
3030
private static int nodeIndex = 0;
3131

3232
private static final String API_KEY_HEADER = "X-TYPESENSE-API-KEY";
33-
private static final Logger logger = LogManager.getLogger(ApiCall.class);
33+
private static final Logger logger = LoggerFactory.getLogger(ApiCall.class);
3434
private final OkHttpClient client;
3535
private final String apiKey;
3636
private final Duration retryInterval;
@@ -150,7 +150,6 @@ <Q, R> R delete(String endpoint, Q queryParameters, Class<R> responseClass) thro
150150
<Q, T> T makeRequest(String endpoint, Q queryParameters, Request.Builder requestBuilder,
151151
Class<T> responseClass) throws Exception {
152152
int num_tries = 0;
153-
Logger logger = LogManager.getLogger(ApiCall.class);
154153
Exception lastException = new TypesenseError("Unknown client error", 400);
155154

156155
while (num_tries < this.configuration.numRetries) {
@@ -193,12 +192,14 @@ <Q, T> T makeRequest(String endpoint, Q queryParameters, Request.Builder request
193192

194193
this.setNodeHealthStatus(node, false);
195194
lastException = e;
196-
logger.trace("Request to " + node.host + " failed because: " + e.getMessage());
197-
logger.trace("Sleeping for " + this.retryInterval.getSeconds() + "s and then retrying request");
195+
196+
logger.debug("Request to " + node.host + " failed because: " + e.getMessage());
197+
logger.debug("Sleeping for " + this.retryInterval.getSeconds() + "s and then retrying request");
198+
198199
try {
199200
Thread.sleep(this.retryInterval.getSeconds() * 1000);
200-
} catch (InterruptedException interruptedException) {
201-
logger.error("Error while sleeping.", interruptedException);
201+
} catch (InterruptedException ignored) {
202+
202203
}
203204
}
204205
}

0 commit comments

Comments
 (0)