Updated custom logging implementation
This commit is contained in:
parent
f05345112f
commit
75ac7de5cd
|
@ -12,7 +12,7 @@
|
|||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>1.4.3.RELEASE</version>
|
||||
</parent>
|
||||
|
||||
|
||||
<dependencies>
|
||||
<!-- Spring Boot Dependencies -->
|
||||
<dependency>
|
||||
|
@ -60,5 +60,14 @@
|
|||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Apache common IO for utility -->
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>2.4</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
|
@ -7,6 +7,9 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
|
||||
import org.springframework.web.util.ContentCachingRequestWrapper;
|
||||
|
||||
import com.baeldung.rest.log.util.RequestLoggingUtil;
|
||||
|
||||
@Component
|
||||
public class TaxiFareRequestInterceptor extends HandlerInterceptorAdapter {
|
||||
|
@ -15,7 +18,21 @@ public class TaxiFareRequestInterceptor extends HandlerInterceptorAdapter {
|
|||
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
||||
LOGGER.info("REQUEST URI: " + request.getRequestURI());
|
||||
String postData = null;
|
||||
HttpServletRequest requestCacheWrapperObject = null;
|
||||
try {
|
||||
// Uncomment to produce the stream closed issue
|
||||
// postData = RequestLoggingUtil.getStringFromInputStream(request.getInputStream());
|
||||
|
||||
// To overcome request stream closed issue
|
||||
requestCacheWrapperObject = new ContentCachingRequestWrapper(request);
|
||||
requestCacheWrapperObject.getParameterMap();
|
||||
} catch (Exception exception) {
|
||||
exception.printStackTrace();
|
||||
} finally {
|
||||
postData = RequestLoggingUtil.readPayload(requestCacheWrapperObject);
|
||||
LOGGER.info("REQUEST DATA: " + postData);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,13 +1,10 @@
|
|||
package com.baeldung.rest.log.config;
|
||||
|
||||
import javax.servlet.annotation.WebFilter;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.filter.CommonsRequestLoggingFilter;
|
||||
|
||||
@Configuration
|
||||
@WebFilter
|
||||
public class RequestLoggingFilterConfig {
|
||||
|
||||
@Bean
|
||||
|
|
|
@ -34,7 +34,10 @@ public class TaxiFareController {
|
|||
@ResponseBody
|
||||
public String calculateTaxiFare(@RequestBody @Valid TaxiRide taxiRide) {
|
||||
LOGGER.debug("calculateTaxiFare() - START");
|
||||
return taxiFareCalculatorService.calculateFare(taxiRide);
|
||||
String totalFare = taxiFareCalculatorService.calculateFare(taxiRide);
|
||||
LOGGER.debug("calculateTaxiFare() - Total Fare : {}",totalFare);
|
||||
LOGGER.debug("calculateTaxiFare() - END");
|
||||
return totalFare;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue