Reputation: 390
I am using CommonsRequestLoggingFilter
to log payload of incoming request . But for one method i don't want to log the payload as it contains user confidential data . I have following configuration in web.xml
<filter>
<filter-name>LogFilter</filter-name>
<filter-class>org.springframework.web.filter.CommonsRequestLoggingFilter</filter-class>
<init-param>
<param-name>includePayload</param-name>
<param-value >true</param-value>
</init-param>
<init-param>
<param-name>includeQueryString</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>MaxPayloadLength</param-name>
<param-value>10000</param-value>
</init-param>
</filter>
Help me in restricting with one method .
Thanks in advance
Upvotes: 3
Views: 1113
Reputation: 2828
What worked for me was:
@Bean
public CommonsRequestLoggingFilter logFilter() {
CommonsRequestLoggingFilter filter = new CommonsRequestLoggingFilter() {
@Override
protected boolean shouldLog(HttpServletRequest request) {
if (!request.getRequestURI().startsWith("/myapp/service1/")) {
return false;
}
return logger.isDebugEnabled();
}
};
return filter;
}
Although I am not very happy with this solution and still trying to find something more elegant.
Upvotes: 0
Reputation: 1313
You could create your own class extending CommonsRequestLoggingFilter and in that class you could do:-
@Override
protected String createMessage(HttpServletRequest request, String prefix, String suffix) {
//based on uri you could print payload or not.
}
Upvotes: 1