1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| @Configuration public class FilterConfig {
@Bean public FilterRegistrationBean filterRegistrationBean() { FilterRegistrationBean<Filter> register = new FilterRegistrationBean<>(); register.setFilter(new TimeFilter()); register.addUrlPatterns("/*"); return register; }
private static class TimeFilter implements Filter { private static Logger log = LoggerFactory.getLogger(TimeFilter.class);
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest req = (HttpServletRequest) request; long start = System.currentTimeMillis(); log.info("{} {}", req.getServletPath(), JSONObject.toJSONString(request.getParameterMap())); chain.doFilter(request, response); log.info("{} {}ms", req.getServletPath(), System.currentTimeMillis() - start); } } }
|