Commit e4011340 by ping.wu

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

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