import java.io.IOException;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.filter.OncePerRequestFilter;
public class LogIPFilter extends OncePerRequestFilter {
private final Logger log = LoggerFactory.getLogger(this.getClass());
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
throws ServletException, IOException {
String ip = request.getHeader("X-Forwarded-For");;
String path=request.getServletPath()+request.getPathInfo();
log.info("IP:["+ip+"],url:["+path+"]");
filterChain.doFilter(request, response);
}
}
网友评论