美文网首页
日志中添加客户端IP的配置方法

日志中添加客户端IP的配置方法

作者: 小芃同学 | 来源:发表于2019-11-19 10:51 被阅读0次
    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);
        }
    }
    

    相关文章

      网友评论

          本文标题:日志中添加客户端IP的配置方法

          本文链接:https://www.haomeiwen.com/subject/ytlwictx.html