Reputation: 539
I am trying to intercept every HTTP request that comes into my Spring Boot application. For this I have a LoggingInterceptor as follows:
@Component
public class LoggingInterceptor extends HandlerInterceptorAdapter {
private static final Logger logger = LoggerFactory.getLogger(LoggingInterceptor.class);
public LoggingInterceptor() {
super();
logger.debug("LoggingInteceptor constructor");
}
@Override
public boolean preHandle(HttpServletRequest request,
HttpServletResponse response, Object handler) throws Exception {
logger.debug("LoggingInteceptor: Intercepted " + request.getRequestURI());
return true;
}
}
Then, I have an @Configuration class for adding the interceptor to the registry as follows:
@EnableWebMvc
@Configuration
public class LoggingConfig extends WebMvcConfigurerAdapter {
@Autowired
LoggingInterceptor loggingInterceptor;
public void addInterceptors(InterceptorRegistry registry){
registry.addInterceptor(loggingInterceptor);
}
}
However, I just cannot see any of the logger statements. Is there something more I need to do to get this going?
Upvotes: 0
Views: 192
Reputation: 24561
Your configuration looks fine. Also registry.addInterceptor(loggingInterceptor);
call would fail if interceptor would be null, therefore it seems to be correctly wired.
Therefore I would verify:
EDIT:
OK, so comment confirmed that you your problem is my first point. You need to find out logging configuration file (e.g. log4j.properties, log4j,xml or logback.xml) and change log level from INFO to DEBUG there.
Upvotes: 1