diff --git a/tosan-httpclient-spring-boot-resttemplate-starter/src/main/java/com/tosan/client/http/resttemplate/starter/impl/interceptor/HttpLoggingInterceptor.java b/tosan-httpclient-spring-boot-resttemplate-starter/src/main/java/com/tosan/client/http/resttemplate/starter/impl/interceptor/HttpLoggingInterceptor.java index 9c5636c..fbf09f3 100644 --- a/tosan-httpclient-spring-boot-resttemplate-starter/src/main/java/com/tosan/client/http/resttemplate/starter/impl/interceptor/HttpLoggingInterceptor.java +++ b/tosan-httpclient-spring-boot-resttemplate-starter/src/main/java/com/tosan/client/http/resttemplate/starter/impl/interceptor/HttpLoggingInterceptor.java @@ -32,18 +32,21 @@ public ClientHttpResponse intercept(HttpRequest request, byte[] requestBody, Cli log.info(httpLoggingInterceptorUtil.getRequestDetailContent(request, requestBody, webServiceName)); } ClientHttpResponse response; + long startTime = System.currentTimeMillis(); try { response = ex.execute(request, requestBody); if (log.isInfoEnabled()) { HttpResponseWrapper responseWrapper = new HttpResponseWrapper(response); - log.info(httpLoggingInterceptorUtil.getResponseDetailContent(responseWrapper, webServiceName)); + log.info(httpLoggingInterceptorUtil.getResponseDetailContent(responseWrapper, webServiceName, + System.currentTimeMillis() - startTime)); return responseWrapper; } else { return response; } } catch (IOException e) { if (log.isInfoEnabled()) { - log.info(httpLoggingInterceptorUtil.getExceptionDetailContent(e, webServiceName)); + log.info(httpLoggingInterceptorUtil.getExceptionDetailContent(e, webServiceName, + System.currentTimeMillis() - startTime)); } throw new HttpClientRequestExecuteException(e.getMessage(), e); } diff --git a/tosan-httpclient-spring-boot-resttemplate-starter/src/main/java/com/tosan/client/http/resttemplate/starter/util/HttpLoggingInterceptorUtil.java b/tosan-httpclient-spring-boot-resttemplate-starter/src/main/java/com/tosan/client/http/resttemplate/starter/util/HttpLoggingInterceptorUtil.java index 9a54471..047422c 100644 --- a/tosan-httpclient-spring-boot-resttemplate-starter/src/main/java/com/tosan/client/http/resttemplate/starter/util/HttpLoggingInterceptorUtil.java +++ b/tosan-httpclient-spring-boot-resttemplate-starter/src/main/java/com/tosan/client/http/resttemplate/starter/util/HttpLoggingInterceptorUtil.java @@ -65,9 +65,10 @@ public String getRequestDetailContent(HttpRequest request, byte[] body, String w return toJson(requestData); } - public String getResponseDetailContent(ClientHttpResponse response, String webServiceName) throws IOException { + public String getResponseDetailContent(ClientHttpResponse response, String webServiceName, long elapsedTime) throws IOException { final Map responseData = new LinkedHashMap<>(); responseData.put("invoked", webServiceName); + responseData.put("duration", elapsedTime / 1000.0 + "s"); responseData.put("status", response.getStatusCode()); if (!response.getHeaders().isEmpty()) { responseData.put("headers", getMaskedHeaders(response.getHeaders())); @@ -80,9 +81,10 @@ public String getResponseDetailContent(ClientHttpResponse response, String webSe return toJson(responseData); } - public String getExceptionDetailContent(Exception exception, String webServiceName) { + public String getExceptionDetailContent(Exception exception, String webServiceName, long elapsedTime) { final Map exceptionData = new LinkedHashMap<>(); exceptionData.put("invoked", webServiceName); + exceptionData.put("duration", elapsedTime / 1000.0 + "s"); exceptionData.put("exception", exception.getClass().getSimpleName()); exceptionData.put("message", exception.getMessage()); return toJson(exceptionData);