|
|
@@ -6,14 +6,13 @@ import com.tzld.piaoquan.ad.engine.commons.util.JSONUtils;
|
|
|
import com.tzld.piaoquan.ad.engine.commons.util.TraceUtils;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.aspectj.lang.ProceedingJoinPoint;
|
|
|
-import org.aspectj.lang.annotation.AfterThrowing;
|
|
|
import org.aspectj.lang.annotation.Around;
|
|
|
import org.aspectj.lang.annotation.Aspect;
|
|
|
import org.aspectj.lang.annotation.Pointcut;
|
|
|
import org.aspectj.lang.reflect.MethodSignature;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
-import java.util.Collections;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
/**
|
|
|
@@ -34,6 +33,8 @@ public class ControllerAspect {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ @Value("${aspect_log_switch:false}")
|
|
|
+ private Boolean aspectLogSwitch;
|
|
|
|
|
|
@Around("logPointcut() && !excludePointcut()")
|
|
|
public Object around(ProceedingJoinPoint pjp) throws Throwable {
|
|
|
@@ -44,12 +45,13 @@ public class ControllerAspect {
|
|
|
|
|
|
String param = JSONUtils.toJson(pjp.getArgs(), Sets.newHashSet("statisticsLog"));
|
|
|
|
|
|
- log.info("request className=[{}], method=[{}], param=[{}]", className, signature.getName(), param);
|
|
|
+ if (Boolean.TRUE.equals(aspectLogSwitch)) {
|
|
|
+ log.info("request className=[{}], method=[{}], param=[{}]", className, signature.getName(), param);
|
|
|
+ }
|
|
|
Object result = pjp.proceed();
|
|
|
- if (result != null && result instanceof String) {
|
|
|
- log.info("request method=[{}] param=[{}] result=[{}] cost=[{}]", signature.getName(), param, result, stopwatch.stop().elapsed(TimeUnit.MILLISECONDS));
|
|
|
- } else {
|
|
|
- log.info("request method=[{}] param=[{}] result=[{}] cost=[{}]", signature.getName(), param, JSONUtils.toJson(result), stopwatch.stop().elapsed(TimeUnit.MILLISECONDS));
|
|
|
+ if (Boolean.TRUE.equals(aspectLogSwitch)) {
|
|
|
+ String resultStr = (result instanceof String) ? (String) result : JSONUtils.toJson(result);
|
|
|
+ log.info("request method=[{}] param=[{}] result=[{}] cost=[{}]", signature.getName(), param, resultStr, stopwatch.stop().elapsed(TimeUnit.MILLISECONDS));
|
|
|
}
|
|
|
TraceUtils.removeMDC();
|
|
|
return result;
|