|
|
@@ -3,6 +3,8 @@ package me.zhengjie.aspect;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.serializer.SerializerFeature;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import me.zhengjie.utils.IpAddressUtil;
|
|
|
+
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.aspectj.lang.JoinPoint;
|
|
|
import org.aspectj.lang.Signature;
|
|
|
@@ -21,19 +23,15 @@ import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
import java.util.Objects;
|
|
|
|
|
|
-
|
|
|
@Slf4j
|
|
|
@Aspect
|
|
|
@Component
|
|
|
public class LogRequestParam {
|
|
|
-
|
|
|
|
|
|
@Pointcut("execution(* me.zhengjie.application.*.controller..*.*(..))")
|
|
|
public void pointCut() {
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
@Before(value = "pointCut()")
|
|
|
public void doBefore(JoinPoint joinPoint) {
|
|
|
try {
|
|
|
@@ -44,8 +42,8 @@ public class LogRequestParam {
|
|
|
return;
|
|
|
}
|
|
|
HttpServletRequest request = servletRequestAttributes.getRequest();
|
|
|
-
|
|
|
- String ip = request.getRemoteAddr();
|
|
|
+ //得到请求的ip地址
|
|
|
+ String ip = IpAddressUtil.getIpAddress(request);
|
|
|
|
|
|
String uri = request.getRequestURI();
|
|
|
|
|
|
@@ -95,14 +93,14 @@ public class LogRequestParam {
|
|
|
}
|
|
|
int status = response.getStatus();
|
|
|
HttpServletRequest request = servletRequestAttributes.getRequest();
|
|
|
- String json=JSON.toJSONString(result, SerializerFeature.WriteMapNullValue);
|
|
|
- //打印输出的值
|
|
|
- if(StringUtils.isNotBlank(json)&& json.length()<1500) {
|
|
|
+ String json = JSON.toJSONString(result, SerializerFeature.WriteMapNullValue);
|
|
|
+ // 打印输出的值
|
|
|
+ if (StringUtils.isNotBlank(json) && json.length() < 1500) {
|
|
|
String uri = request.getRequestURI();
|
|
|
Object obj[] = { status, uri, json };
|
|
|
log.info("[reponse] - status: {} , url:{} ,result:{}", obj);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|