Commit e4011340 by ping.wu

订单聚合层Feign打印日志修改

parent 6223961f
......@@ -16,7 +16,7 @@ public @interface LogIgnoreFeign {
* 是否打印日志,true打印,false不打印,注意设置成false状态码和状态码信息都不会打印
* @return
*/
boolean printLog() default true;
boolean printLog() default false;
/**
* printLog 设置成true的时候,可以排除哪些状态码的响应不用打印响应报文,只会打印状态码
......
......@@ -4,10 +4,11 @@ import cn.freemud.annotations.LogIgnore;
import cn.freemud.annotations.LogIgnoreFeign;
import cn.freemud.entities.vo.ThirdPartLogVo;
import cn.freemud.utils.AppLogUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.freemud.application.sdk.api.base.SDKCommonBaseContextWare;
import com.freemud.application.sdk.api.log.LogThreadLocal;
import com.freemud.application.sdk.api.log.ThirdPartyLog;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.Around;
......@@ -30,7 +31,6 @@ import java.lang.reflect.Method;
@Aspect
@Component
@Slf4j
public class LogIgnoreFeignAspect {
/**
* 是否打印响应报文日志,默认是false,若为true会覆盖注解里面的{@link LogIgnore}配置,输出响应报文里面所有的信息
......@@ -61,14 +61,17 @@ public class LogIgnoreFeignAspect {
Method currentMethod = sig.getDeclaringType().getDeclaredMethod(msig.getName(), msig.getParameterTypes());
Object logReult = result;
ThirdPartLogVo thirdPartLogVo = AppLogUtil.createThirdPartLogVo(joinPoint);
// 打印第三方出参日志
if (!this.printFeignResponseBodyLog) {
LogIgnoreFeign logIgnore = currentMethod.getAnnotation(LogIgnoreFeign.class);
if (logIgnore != null && logIgnore.printLog()) {
String statusCodeValue = org.apache.commons.beanutils.BeanUtils.getProperty(result, logIgnore.statusCodeFieldName());
String messageValue = org.apache.commons.beanutils.BeanUtils.getProperty(result, logIgnore.messageFieldName());
String statusCodeValue = "ignore";
String messageValue = "ignore";
// 打印第三方出参日志 如果feign方法没有IgnoreFeignLogAnnotation注解,全部打日志,但是由于statusCodeValue = "ignore",是不是触发日志告警的
LogIgnoreFeign logIgnore = currentMethod.getAnnotation(LogIgnoreFeign.class);
if (logIgnore != null) {
JSONObject json = JSON.parseObject(JSON.toJSONString(result));
statusCodeValue = json.getString(logIgnore.statusCodeFieldName());
messageValue = json.getString(logIgnore.messageFieldName());
if (!this.printFeignResponseBodyLog && !logIgnore.printLog()) {
//todo 当排除了这个状态码不打印响应的具体内容只会打印状态码和状态描述信息
String[] excludeStatusCodes = logIgnore.excludeStatusCodes();
//当排除了这个状态码不打印响应的具体内容只会打印状态码和状态描述信息
if (!StringUtils.isEmpty(statusCodeValue) && this.containStatusCode(excludeStatusCodes, statusCodeValue)) {
logReult = result.getClass().newInstance();
org.apache.commons.beanutils.BeanUtils.setProperty(logReult, logIgnore.statusCodeFieldName(), statusCodeValue);
......@@ -76,7 +79,7 @@ public class LogIgnoreFeignAspect {
}
}
}
ThirdPartyLog.infoConvertJson(LogThreadLocal.getTrackingNo(), SDKCommonBaseContextWare.getAppName(), start, System.currentTimeMillis(),
ThirdPartyLog.infoConvertJson(statusCodeValue, messageValue, start, System.currentTimeMillis(),
thirdPartLogVo.getUri(), thirdPartLogVo.getRequestBody(), logReult);
}
} catch (Exception e) {
......
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