Commit 9e66fbad by hanghang.wang

修改日志打印内容,跟进打印多次问题

parent 595a014c
...@@ -6,7 +6,6 @@ import com.freemud.application.sdk.api.exception.IgnoreErrorAnnotation; ...@@ -6,7 +6,6 @@ import com.freemud.application.sdk.api.exception.IgnoreErrorAnnotation;
import com.freemud.application.sdk.api.log.*; import com.freemud.application.sdk.api.log.*;
import com.freemud.application.sdk.api.service.EmailAlertService; import com.freemud.application.sdk.api.service.EmailAlertService;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.beanutils.BeanUtils; import org.apache.commons.beanutils.BeanUtils;
import org.aspectj.lang.JoinPoint; import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.ProceedingJoinPoint;
...@@ -32,10 +31,13 @@ import java.util.Arrays; ...@@ -32,10 +31,13 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
/**
* @author freemud_whh
*/
@Aspect @Aspect
@Component @Component
@Slf4j
public class ControllerLogAop implements Ordered { public class ControllerLogAop implements Ordered {
@Autowired @Autowired
private EmailAlertService emailAlertService; private EmailAlertService emailAlertService;
...@@ -51,7 +53,6 @@ public class ControllerLogAop implements Ordered { ...@@ -51,7 +53,6 @@ public class ControllerLogAop implements Ordered {
@Value("${exclude-print-body-log-methods:findNearPickUpStores,getMenuCategory}") @Value("${exclude-print-body-log-methods:findNearPickUpStores,getMenuCategory}")
private volatile List<String> excludePrintBodyLogMethods = Lists.newArrayList(); private volatile List<String> excludePrintBodyLogMethods = Lists.newArrayList();
@Pointcut("@annotation(cn.freemud.aop.LogIgnore)") @Pointcut("@annotation(cn.freemud.aop.LogIgnore)")
public void pointcut() { public void pointcut() {
} }
...@@ -78,7 +79,6 @@ public class ControllerLogAop implements Ordered { ...@@ -78,7 +79,6 @@ public class ControllerLogAop implements Ordered {
List logArgs = this.getLogArgs(currentMethod, joinPoint); List logArgs = this.getLogArgs(currentMethod, joinPoint);
String requestData = JSON.toJSONString(logArgs); String requestData = JSON.toJSONString(logArgs);
LogIgnore logIgnore = currentMethod.getAnnotation(LogIgnore.class); LogIgnore logIgnore = currentMethod.getAnnotation(LogIgnore.class);
// log.info("startTime={}-->TrackingNo={}-->logMessage= {}-->url={}-->requestData={} ::start",startTime,LogThreadLocal.getTrackingNo(),logIgnore.logMessage(),logMethod,requestData);
Object object = joinPoint.proceed(); Object object = joinPoint.proceed();
Object logObj = object; Object logObj = object;
if (logIgnore != null && logIgnore.printLog()) { if (logIgnore != null && logIgnore.printLog()) {
...@@ -112,8 +112,6 @@ public class ControllerLogAop implements Ordered { ...@@ -112,8 +112,6 @@ public class ControllerLogAop implements Ordered {
if (excludeStatusCodes == null || excludeStatusCodes.length == 0) { if (excludeStatusCodes == null || excludeStatusCodes.length == 0) {
return false; return false;
} }
for (int i = 0; i < excludeStatusCodes.length; i++) { for (int i = 0; i < excludeStatusCodes.length; i++) {
if (excludeStatusCodes[i].equals(statusCodeValue)) { if (excludeStatusCodes[i].equals(statusCodeValue)) {
return true; return true;
...@@ -143,18 +141,15 @@ public class ControllerLogAop implements Ordered { ...@@ -143,18 +141,15 @@ public class ControllerLogAop implements Ordered {
} else { } else {
msig = (MethodSignature) sig; msig = (MethodSignature) sig;
Object target = joinPoint.getTarget(); Object target = joinPoint.getTarget();
try { try {
currentMethod = target.getClass().getMethod(msig.getName(), msig.getParameterTypes()); currentMethod = target.getClass().getMethod(msig.getName(), msig.getParameterTypes());
} catch (NoSuchMethodException var19) { } catch (NoSuchMethodException var19) {
var19.printStackTrace(); var19.printStackTrace();
} }
StringBuilder logMethod = new StringBuilder(joinPoint.getSignature().getDeclaringTypeName()); StringBuilder logMethod = new StringBuilder(joinPoint.getSignature().getDeclaringTypeName());
logMethod.append("."); logMethod.append(".");
logMethod.append(joinPoint.getSignature().getName()); logMethod.append(joinPoint.getSignature().getName());
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
try { try {
Class<?> clz = e.getClass(); Class<?> clz = e.getClass();
boolean clzHasAnno = clz.isAnnotationPresent(IgnoreErrorAnnotation.class); boolean clzHasAnno = clz.isAnnotationPresent(IgnoreErrorAnnotation.class);
...@@ -167,7 +162,6 @@ public class ControllerLogAop implements Ordered { ...@@ -167,7 +162,6 @@ public class ControllerLogAop implements Ordered {
ErrorLog.errorConvertJson(SDKCommonBaseContextWare.getAppName(), logMethod.toString(), "出错:" + e.getMessage(), request, startTime, System.currentTimeMillis(), this.getLogArgs(currentMethod, joinPoint), e); ErrorLog.errorConvertJson(SDKCommonBaseContextWare.getAppName(), logMethod.toString(), "出错:" + e.getMessage(), request, startTime, System.currentTimeMillis(), this.getLogArgs(currentMethod, joinPoint), e);
LogThreadLocal.removeTrackingNo(); LogThreadLocal.removeTrackingNo();
} }
} }
} }
...@@ -179,7 +173,6 @@ public class ControllerLogAop implements Ordered { ...@@ -179,7 +173,6 @@ public class ControllerLogAop implements Ordered {
if (args != null && args.length != 0) { if (args != null && args.length != 0) {
List logArgs = new ArrayList(); List logArgs = new ArrayList();
Parameter[] parameters = method.getParameters(); Parameter[] parameters = method.getParameters();
for (int j = 0; j < parameters.length; ++j) { for (int j = 0; j < parameters.length; ++j) {
Parameter parameter = parameters[j]; Parameter parameter = parameters[j];
LogParams logParams = (LogParams) parameter.getAnnotation(LogParams.class); LogParams logParams = (LogParams) parameter.getAnnotation(LogParams.class);
...@@ -187,7 +180,6 @@ public class ControllerLogAop implements Ordered { ...@@ -187,7 +180,6 @@ public class ControllerLogAop implements Ordered {
logArgs.add(args[j]); logArgs.add(args[j]);
} }
} }
return logArgs; return logArgs;
} else { } else {
return null; return null;
......
...@@ -84,7 +84,6 @@ public class WebAspect { ...@@ -84,7 +84,6 @@ public class WebAspect {
@Value("${print-feign-response-body-log-shop-cart:false}") @Value("${print-feign-response-body-log-shop-cart:false}")
private volatile boolean printFeignResponseBodyLogForShopCart = false; private volatile boolean printFeignResponseBodyLogForShopCart = false;
@Pointcut("execution(* cn.freemud.controller..*.*(..))") @Pointcut("execution(* cn.freemud.controller..*.*(..))")
public void webAspect() { public void webAspect() {
} }
...@@ -169,7 +168,6 @@ public class WebAspect { ...@@ -169,7 +168,6 @@ public class WebAspect {
if (sig instanceof MethodSignature) { if (sig instanceof MethodSignature) {
msig = (MethodSignature) sig; msig = (MethodSignature) sig;
Method currentMethod = sig.getDeclaringType().getDeclaredMethod(msig.getName(), msig.getParameterTypes()); Method currentMethod = sig.getDeclaringType().getDeclaredMethod(msig.getName(), msig.getParameterTypes());
Object logReult = result; Object logReult = result;
ThirdPartLogVo thirdPartLogVo = LogUtil.createThirdPartLogVo(joinPoint); ThirdPartLogVo thirdPartLogVo = LogUtil.createThirdPartLogVo(joinPoint);
// 打印第三方出参日志 // 打印第三方出参日志
...@@ -189,7 +187,6 @@ public class WebAspect { ...@@ -189,7 +187,6 @@ public class WebAspect {
} }
ThirdPartyLog.infoConvertJson(LogThreadLocal.getTrackingNo(), SDKCommonBaseContextWare.getAppName(), start, System.currentTimeMillis(), ThirdPartyLog.infoConvertJson(LogThreadLocal.getTrackingNo(), SDKCommonBaseContextWare.getAppName(), start, System.currentTimeMillis(),
thirdPartLogVo.getUri(), thirdPartLogVo.getRequestBody(), logReult); thirdPartLogVo.getUri(), thirdPartLogVo.getRequestBody(), logReult);
} }
} catch (Exception e) { } catch (Exception e) {
log.error("WebAspect Feign Log Ignore error {}", ExceptionUtils.getMessage(e)); log.error("WebAspect Feign Log Ignore error {}", ExceptionUtils.getMessage(e));
...@@ -197,13 +194,11 @@ public class WebAspect { ...@@ -197,13 +194,11 @@ public class WebAspect {
return result; return result;
} }
/** /**
* 20201231改造SDK日志打印判断 * 20201231改造SDK日志打印判断
* 根据printFeignResponseBodyLog判断是否开启打印 * 根据printFeignResponseBodyLog判断是否开启打印
* 后续将模块内SDK整合为feign请求,此次暂时不用 * 后续将模块内SDK整合为feign请求,此次暂时不用
*/ */
/** /**
* @Pointcut("@annotation(com.freemud.application.sdk.api.log.ThirdPartyLog)") public void restTemplateLog() { * @Pointcut("@annotation(com.freemud.application.sdk.api.log.ThirdPartyLog)") public void restTemplateLog() {
* } * }
...@@ -252,7 +247,6 @@ public class WebAspect { ...@@ -252,7 +247,6 @@ public class WebAspect {
* } * }
*/ */
public String getNotFilterUrl(String redisKey, String configKey) { public String getNotFilterUrl(String redisKey, String configKey) {
String notFilterUrl; String notFilterUrl;
try { try {
...@@ -270,7 +264,8 @@ public class WebAspect { ...@@ -270,7 +264,8 @@ public class WebAspect {
return notFilterUrl; return notFilterUrl;
} }
private boolean containStatusCode(String[] excludeStatusCodes, String statusCodeValue) { private boolean containStatusCode(String[] excludeStatusCodes,
String statusCodeValue) {
if (excludeStatusCodes == null || excludeStatusCodes.length == 0) { if (excludeStatusCodes == null || excludeStatusCodes.length == 0) {
return false; return false;
} }
...@@ -282,5 +277,4 @@ public class WebAspect { ...@@ -282,5 +277,4 @@ public class WebAspect {
return false; return false;
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment