|
@@ -0,0 +1,64 @@
|
|
|
+//package com.css.simulation.resource.aspect;
|
|
|
+//
|
|
|
+//import api.common.pojo.po.WebLog;
|
|
|
+//import lombok.extern.slf4j.Slf4j;
|
|
|
+//import org.aspectj.lang.JoinPoint;
|
|
|
+//import org.aspectj.lang.ProceedingJoinPoint;
|
|
|
+//import org.aspectj.lang.Signature;
|
|
|
+//import org.aspectj.lang.annotation.*;
|
|
|
+//import org.aspectj.lang.reflect.MethodSignature;
|
|
|
+//import org.springframework.stereotype.Component;
|
|
|
+//import org.springframework.web.context.request.RequestContextHolder;
|
|
|
+//import org.springframework.web.context.request.ServletRequestAttributes;
|
|
|
+//import sun.net.util.URLUtil;
|
|
|
+//
|
|
|
+//import javax.servlet.http.HttpServletRequest;
|
|
|
+//import java.lang.reflect.Method;
|
|
|
+//import java.util.HashMap;
|
|
|
+//import java.util.Map;
|
|
|
+//
|
|
|
+///**
|
|
|
+// * 统一日志处理切面 * Created by 石磊
|
|
|
+// */
|
|
|
+//@Aspect
|
|
|
+//@Component
|
|
|
+//@Slf4j
|
|
|
+//public class WebLogAspect {
|
|
|
+//
|
|
|
+// @Pointcut("execution(public * com.*.controller.*.*(..))")
|
|
|
+// public void webLog() {
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Before("webLog()")
|
|
|
+// public void doBefore(JoinPoint joinPoint) throws Throwable {
|
|
|
+// }
|
|
|
+//
|
|
|
+// @AfterReturning(value = "webLog()", returning = "ret")
|
|
|
+// public void doAfterReturning(Object ret) throws Throwable {
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Around("webLog()")
|
|
|
+// public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable {
|
|
|
+// long startTime = System.currentTimeMillis(); //获取当前请求对象
|
|
|
+// ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
|
|
+// HttpServletRequest request = attributes.getRequest(); //记录请求信息(通过Logstash传入Elasticsearch)
|
|
|
+// WebLog webLog = new WebLog();
|
|
|
+// Object result = joinPoint.proceed();
|
|
|
+// Signature signature = joinPoint.getSignature();
|
|
|
+// MethodSignature methodSignature = (MethodSignature) signature;
|
|
|
+// Method method = methodSignature.getMethod();
|
|
|
+// if (method.isAnnotationPresent(ApiOperation.class)) {
|
|
|
+// ApiOperation log = method.getAnnotation(ApiOperation.class);
|
|
|
+// webLog.setDescription(log.value());
|
|
|
+// }
|
|
|
+// long endTime = System.currentTimeMillis();
|
|
|
+// String urlStr = request.getRequestURL().toString();
|
|
|
+// webLog.setBasePath(StrUtil.removeSuffix(urlStr, URLUtil.url(urlStr).getPath()));
|
|
|
+// webLog.setIp(request.getRemoteUser());
|
|
|
+// Map<String, Object> logMap = new HashMap<>();
|
|
|
+// logMap.put("spendTime", webLog.getSpendTime());
|
|
|
+// logMap.put("description", webLog.getDescription());
|
|
|
+// LOGGER.info("{}", JSONUtil.parse(webLog));
|
|
|
+// return result;
|
|
|
+// }
|
|
|
+//}
|