|
@@ -10,11 +10,13 @@ import org.aspectj.lang.annotation.AfterReturning;
|
|
|
import org.aspectj.lang.annotation.Aspect;
|
|
|
import org.aspectj.lang.annotation.Before;
|
|
|
import org.aspectj.lang.annotation.Pointcut;
|
|
|
+import org.slf4j.MDC;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import java.lang.reflect.Method;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.List;
|
|
|
|
|
@@ -31,6 +33,15 @@ public class WebLogAspect {
|
|
|
@Autowired
|
|
|
private HttpServletRequest request;
|
|
|
|
|
|
+ private long startTime ;
|
|
|
+
|
|
|
+ // 不打印日志
|
|
|
+ private static List<String> filterUrl;
|
|
|
+ static {
|
|
|
+ filterUrl = new ArrayList<>();
|
|
|
+ filterUrl.add("/manage/scene/edit");
|
|
|
+// filterUrl.add("/web/common/checkWork");
|
|
|
+ }
|
|
|
|
|
|
@Pointcut("execution(* com.gis.web.controller.*.*(..))")//切入点描述 这个是controller包的切入点
|
|
|
public void controllerLog(){}//签名,可以理解成这个切入点的一个名称
|
|
@@ -38,11 +49,23 @@ public class WebLogAspect {
|
|
|
@Before("controllerLog()") //在切入点的方法run之前要干的
|
|
|
public void logBeforeController(JoinPoint joinPoint) throws Exception {
|
|
|
|
|
|
+ startTime = System.currentTimeMillis();
|
|
|
+
|
|
|
+ // 设置链路id, 在logback-spring.xml里用
|
|
|
+ MDC.put("TRACE_ID", startTime+"");
|
|
|
+
|
|
|
+ // 记录下请求内容
|
|
|
+ String remoteAddr = request.getRemoteAddr();
|
|
|
+ String requestURI = request.getRequestURI();
|
|
|
+ log.warn("start : {}, {}, uuid: {}" , request.getMethod(), requestURI, startTime);
|
|
|
+
|
|
|
// 记录请求内容
|
|
|
- log.warn("start : {}" , request.getRequestURI());
|
|
|
log.info("request Method : {}" , request.getMethod());
|
|
|
- log.info("request IP : {}" , request.getRemoteAddr());
|
|
|
- log.info("request Args : {}" , Arrays.toString(joinPoint.getArgs()));
|
|
|
+ log.info("request IP : {}" , remoteAddr);
|
|
|
+// log.info("request Args : {}" , Arrays.toString(joinPoint.getArgs()));
|
|
|
+ if (!filterUrl.contains(requestURI)){
|
|
|
+ log.info("request Args : {}" , Arrays.toString(joinPoint.getArgs()));
|
|
|
+ }
|
|
|
|
|
|
// 获取token
|
|
|
String token = request.getHeader("token");
|
|
@@ -78,7 +101,9 @@ public class WebLogAspect {
|
|
|
public void doAfterReturning(Object ret) throws Throwable {
|
|
|
// 处理完请求,返回内容
|
|
|
// log.info("响应RESPONSE : " + ret.toString());
|
|
|
- log.warn("end : {}", request.getRequestURI());
|
|
|
+// log.warn("end : {}", request.getRequestURI());
|
|
|
+ log.warn("end: {}, {}, uuid: {}, 响应耗时:{} ms", request.getMethod(), request.getRequestURI(), startTime, (System.currentTimeMillis() - startTime));
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/**
|