|
|
@@ -1,119 +0,0 @@
|
|
|
-package com.webflux.launchcommon.config;
|
|
|
-
|
|
|
-
|
|
|
-import cn.hutool.json.JSONUtil;
|
|
|
-import com.mokasz.vnovel.common.core.config.AspectConfig;
|
|
|
-import com.mokasz.vnovel.core.entity.TokenInfo;
|
|
|
-import com.mokasz.vnovel.core.util.TokenInfoUtil;
|
|
|
-import lombok.RequiredArgsConstructor;
|
|
|
-import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.aspectj.lang.JoinPoint;
|
|
|
-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.springframework.core.annotation.Order;
|
|
|
-import org.springframework.stereotype.Component;
|
|
|
-import org.springframework.web.context.request.RequestContextHolder;
|
|
|
-import org.springframework.web.context.request.ServletRequestAttributes;
|
|
|
-
|
|
|
-import javax.servlet.http.HttpServletRequest;
|
|
|
-
|
|
|
-/**
|
|
|
- * @author ljj12094
|
|
|
- */
|
|
|
-@Aspect
|
|
|
-@Component
|
|
|
-@Order
|
|
|
-@RequiredArgsConstructor
|
|
|
-@Slf4j
|
|
|
-public class ParameterLogAspect {
|
|
|
-
|
|
|
- private final AspectConfig aspectConfig;
|
|
|
-
|
|
|
- private static ThreadLocal<Long> startTime = new ThreadLocal<Long>();
|
|
|
-
|
|
|
- private static ThreadLocal<String> requestUrl = new ThreadLocal<String>();
|
|
|
-
|
|
|
- /**
|
|
|
- * 申明一个切点 里面是 execution表达式
|
|
|
- */
|
|
|
- @Pointcut("execution(public * com.mokasz.vnovel.app.controller.*.*(..))")
|
|
|
- private void controllerAspect() {
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 请求method前打印内容
|
|
|
- *
|
|
|
- * @param joinPoint
|
|
|
- */
|
|
|
- @Before(value = "controllerAspect()")
|
|
|
- public void methodBefore(JoinPoint joinPoint) {
|
|
|
- try {
|
|
|
- if (aspectConfig.isEnableParameterLog()) {
|
|
|
- ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
|
|
- HttpServletRequest request = requestAttributes.getRequest();
|
|
|
-
|
|
|
- startTime.set(System.currentTimeMillis());
|
|
|
- requestUrl.set(request.getRequestURL().toString());
|
|
|
-
|
|
|
- //打印请求内容
|
|
|
- StringBuilder sb = new StringBuilder();
|
|
|
- TokenInfo tokenInfo = TokenInfoUtil.getTokenInfo();
|
|
|
- if (tokenInfo != null) {
|
|
|
- sb.append(">>>>>>>>>>令牌信息>>>>>>>>>>");
|
|
|
- sb.append(JSONUtil.toJsonStr(tokenInfo));
|
|
|
- sb.append("<<<<<<<<<<令牌信息<<<<<<<<<<");
|
|
|
- }
|
|
|
- sb.append(">>>>>>>>>>请求内容>>>>>>>>>>");
|
|
|
- sb.append("请求地址:" + request.getRequestURL().toString() + " ");
|
|
|
- sb.append("请求方式:" + request.getMethod() + " ");
|
|
|
- sb.append("请求类方法:" + joinPoint.getSignature() + " ");
|
|
|
-
|
|
|
- for (Object o : joinPoint.getArgs()) {
|
|
|
- try {
|
|
|
- sb.append("请求类方法参数:" + JSONUtil.toJsonStr(o) + " ");
|
|
|
- } catch (Exception e) {
|
|
|
- sb.append("请求类方法参数e:" + o.toString() + " ");
|
|
|
- }
|
|
|
- }
|
|
|
- sb.append("<<<<<<<<<<请求内容<<<<<<<<<<");
|
|
|
-
|
|
|
- log.info(sb.toString());
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("记录参数日志发生异常", e);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 在方法执行完结后打印返回内容
|
|
|
- *
|
|
|
- * @param o
|
|
|
- */
|
|
|
- @AfterReturning(returning = "o", pointcut = "controllerAspect()")
|
|
|
- public void methodAfterReturning(Object o) {
|
|
|
- try {
|
|
|
- if (aspectConfig.isEnableParameterLog()) {
|
|
|
- // 打印返回结果
|
|
|
- StringBuilder sb = new StringBuilder();
|
|
|
- sb.append(">>>>>>>>>>返回内容>>>>>>>>>>");
|
|
|
- sb.append("请求地址:" + requestUrl.get() + " ");
|
|
|
- try {
|
|
|
- sb.append("Response内容:" + JSONUtil.toJsonStr(o) + " ");
|
|
|
- } catch (Exception e) {
|
|
|
- sb.append("Response内容:" + o.toString() + " ");
|
|
|
- }
|
|
|
- sb.append("<<<<<<<<<<返回内容<<<<<<<<<< ");
|
|
|
- sb.append("请求处理时间为:" + (System.currentTimeMillis() - startTime.get()) + "ms ");
|
|
|
-
|
|
|
- log.info(sb.toString());
|
|
|
-
|
|
|
- startTime.remove();
|
|
|
- requestUrl.remove();
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("记录参数日志发生异常", e);
|
|
|
- }
|
|
|
- }
|
|
|
-}
|