package com.gic.haoban.manage.web.utils;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.gic.commons.util.IPUtil;

public class LogInterceptor extends HandlerInterceptorAdapter {

    private static final Logger log = LogManager.getLogger(LogInterceptor.class);

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object object) throws Exception {
        String uri = request.getRequestURI();
        Map<String, String[]> parameterMap = request.getParameterMap();
        String ip = null;
        try {
            ip = IPUtil.getIpAddr(request);
        } catch (Exception e) {
        }
        log.info("请求参数,ip={},url={},参数={}", ip, uri, parameterMap);
        return true;
    }
}
