In my springboot application, we are logging controller requests/responses using the org.springframework.web.util.ContentCachingRequestWrapper
and org.springframework.web.util.ContentCachingResponseWrapper
. Refer below link for the sample code .
CustomLoggingFilter :
There is a interceptor
present in the application. Now the problem is while logging its only the interceptor name coming in className . So, for getting the actual controller name , I tried getting classname in interceptor . But that gives org.springframework.web.util.ContentCachingRequestWrapper
.
CustomWebMvcConfig :
@Configuration
public class CustomWebMvcConfig implements WebMvcConfigurer {
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new CustomLogInterceptor());
}
}
CustomLogInterceptor :
public class CustomLogInterceptor extends HandlerInterceptorAdapter {
private static final Logger logger = LogManager.getLogger(CustomLogInterceptor.class);
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
return true;
}
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception{
//Some operation
}
}
Getting logs in below format:
time="2019-03-18T09:59:51,001Z", thread="[o-auto-1exec-]" ,class=“a.b.c.CustomLoggingFilter ",message=“Payload_1“
time="2019-03-18T09:59:51,001Z", thread="[o-auto-1-xec-1]" ,class=“a.b.c.CustomLoggingFilter ",message=“Payload_2“"
My Question is how to get the actual ControllerClass name in logs instead of the LoggingFilterClass (one which uses the org.springframework.web.util.ContentCachingRequestWrapper
)