diff --git a/pom.xml b/pom.xml
index 07cdb85..269b726 100644
--- a/pom.xml
+++ b/pom.xml
@@ -123,6 +123,11 @@
${jackson-databind.version}
+
+ org.apache.logging.log4j
+ log4j-api
+ ${log4j.version}
+
org.apache.logging.log4j
log4j-core
diff --git a/src/main/groovy/com/tomtom/http/HttpClient.groovy b/src/main/groovy/com/tomtom/http/HttpClient.groovy
index 70ec36d..727ed91 100644
--- a/src/main/groovy/com/tomtom/http/HttpClient.groovy
+++ b/src/main/groovy/com/tomtom/http/HttpClient.groovy
@@ -20,12 +20,15 @@ import com.fasterxml.jackson.databind.ObjectMapper
import com.tomtom.http.response.Response
import org.apache.hc.client5.http.classic.HttpClient as ApacheHttpClient
import org.apache.hc.client5.http.impl.classic.HttpClientBuilder
+import org.apache.logging.log4j.LogManager
+import org.apache.logging.log4j.Logger
import static com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES
import static org.apache.hc.client5.http.routing.RoutingSupport.determineHost
class HttpClient {
+ private static Logger logger = LogManager.getLogger(HttpClient)
private static ApacheHttpClient client
final RequestBuilder builder
@@ -262,12 +265,15 @@ class HttpClient {
private Response performRequest(Map properties) {
def request = builder.request properties
- client.execute(determineHost(request), request, response -> {
+ def response = client.execute(determineHost(request), request, response -> {
parser.parse(
response,
properties['expecting'] as Class,
properties['of'] as Class)
})
+ logger.info("Request: ${request}")
+ logger.info("Response: ${response}")
+ return response
}
}
diff --git a/src/main/groovy/com/tomtom/http/ResponseParser.groovy b/src/main/groovy/com/tomtom/http/ResponseParser.groovy
index 2293089..797ae69 100644
--- a/src/main/groovy/com/tomtom/http/ResponseParser.groovy
+++ b/src/main/groovy/com/tomtom/http/ResponseParser.groovy
@@ -24,10 +24,13 @@ import groovy.transform.PackageScope
import org.apache.hc.core5.http.HttpEntity
import org.apache.hc.core5.http.HttpResponse
import org.apache.hc.core5.http.io.entity.EntityUtils
+import org.apache.logging.log4j.LogManager
+import org.apache.logging.log4j.Logger
@PackageScope
class ResponseParser {
+ private static Logger logger = LogManager.getLogger(HttpClient)
private mapper = new ObjectMapper()
Response parse(HttpResponse response, Class type, Class subtype) {
@@ -50,7 +53,7 @@ class ResponseParser {
try {
return mapper.readValue(content, type)
} catch (Exception e) {
- println "Failed to deserialize $content to $rawType due to $e.message, defaulting to string"
+ logger.warn "Failed to deserialize $content to $rawType due to $e.message, defaulting to string"
}
}
content