content: package com.xuan.chapter3.logfilter.starter.filter;
  
  import org.slf4j.Logger;
  import org.slf4j.LoggerFactory;
  
  import javax.servlet.Filter;
  import javax.servlet.FilterChain;
  import javax.servlet.FilterConfig;
  import javax.servlet.ServletException;
  import javax.servlet.ServletRequest;
  import javax.servlet.ServletResponse;
  import javax.servlet.http.HttpServletRequest;
  import java.io.IOException;
  
  /**
   * Created by xuan on 2018/4/9.
   */
  public class LogFilter implements Filter {
  
  
      private Logger logger = LoggerFactory.getLogger(LogFilter.class);
  
      @Override
      public void init(FilterConfig filterConfig) throws ServletException {
          logger.info("logFilter init...");
      }
  
      @Override
      public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
          //  从request中获取到访问的地址，并在控制台中打印出来
          HttpServletRequest request = (HttpServletRequest) servletRequest;
          logger.info("uri {} is working.", request.getRequestURI());
          filterChain.doFilter(servletRequest, servletResponse);
      }
  
      @Override
      public void destroy() {
          logger.info("logFilter destroy...");
  
      }
  }
  