Commit c27c1a6b authored by yanzg's avatar yanzg

Merge remote-tracking branch 'origin/master'

parents ef72d0bc efe3f265
...@@ -5,6 +5,7 @@ import com.yanzuoguang.util.helper.StringHelper; ...@@ -5,6 +5,7 @@ import com.yanzuoguang.util.helper.StringHelper;
/** /**
* 日志处理默认处理函数 * 日志处理默认处理函数
*
* @author 颜佐光 * @author 颜佐光
*/ */
public class LogDefault implements RunnableLog { public class LogDefault implements RunnableLog {
...@@ -35,9 +36,7 @@ public class LogDefault implements RunnableLog { ...@@ -35,9 +36,7 @@ public class LogDefault implements RunnableLog {
info.getMessage() info.getMessage()
)); ));
if (info.getException() != null) { if (info.getException() != null) {
sb.append(System.lineSeparator());
sb.append(info.getException().getClass().getName()); sb.append(info.getException().getClass().getName());
sb.append(System.lineSeparator());
sb.append(info.getException().getMessage()); sb.append(info.getException().getMessage());
} }
......
package com.yanzuoguang.cloud.aop; package com.yanzuoguang.cloud.aop;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.yanzuoguang.cloud.CloudContans;
import com.yanzuoguang.util.cache.MemoryCache; import com.yanzuoguang.util.cache.MemoryCache;
import com.yanzuoguang.util.contants.ResultConstants; import com.yanzuoguang.util.contants.ResultConstants;
import com.yanzuoguang.util.exception.ExceptionHelper; import com.yanzuoguang.util.exception.ExceptionHelper;
...@@ -91,17 +90,7 @@ public class BaseRequestAspect implements ThreadNext.Next { ...@@ -91,17 +90,7 @@ public class BaseRequestAspect implements ThreadNext.Next {
logInterVo.setLogSources(applicationName); logInterVo.setLogSources(applicationName);
//请求URL //请求URL
logInterVo.setInterUrl(url); logInterVo.setInterUrl(url);
List<Object> para = new ArrayList<>(); Object paraTo = getFirstDataParameter(joinPoint.getArgs());
for (Object item : joinPoint.getArgs()) {
if (item instanceof HttpServlet || item instanceof HttpServletResponse || item instanceof HttpServletRequest) {
continue;
}
para.add(item);
}
Object paraTo = para;
if (para.size() == 1) {
paraTo = para.get(0);
}
//请求参数 //请求参数
logInterVo.setContent(JSON.toJSONString(paraTo)); logInterVo.setContent(JSON.toJSONString(paraTo));
//返回参数 //返回参数
...@@ -110,6 +99,37 @@ public class BaseRequestAspect implements ThreadNext.Next { ...@@ -110,6 +99,37 @@ public class BaseRequestAspect implements ThreadNext.Next {
return logInterVo; return logInterVo;
} }
/**
* 获取请求的参数
*
* @param args
* @return
*/
protected Object getFirstDataParameter(Object[] args) {
List<Object> para = getDataParameters(args);
Object paraTo = para;
if (para.size() == 1) {
paraTo = para.get(0);
}
return paraTo;
}
/**
* 获取数据参数
* @param args
* @return
*/
protected List<Object> getDataParameters(Object[] args) {
List<Object> para = new ArrayList<>();
for (Object item : args) {
if (item instanceof HttpServlet || item instanceof HttpServletResponse || item instanceof HttpServletRequest) {
continue;
}
para.add(item);
}
return para;
}
/** /**
* 获取JSON,当Json过长时,截断 * 获取JSON,当Json过长时,截断
* *
...@@ -147,7 +167,7 @@ public class BaseRequestAspect implements ThreadNext.Next { ...@@ -147,7 +167,7 @@ public class BaseRequestAspect implements ThreadNext.Next {
try { try {
String name = joinPoint.getSignature().getName(); String name = joinPoint.getSignature().getName();
Log.info(joinPoint.getSignature().getDeclaringType(), " %s [ %s ] request: %s", Log.info(joinPoint.getSignature().getDeclaringType(), " %s [ %s ] request: %s",
tag, name, this.getMaxString(JsonHelper.serialize(joinPoint.getArgs()))); tag, name, this.getMaxString(JsonHelper.serialize(getFirstDataParameter(joinPoint.getArgs()))));
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
......
...@@ -16,10 +16,9 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -16,10 +16,9 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.util.List;
/** /**
* LogsAspect(接口请求日志切面) * LogsAspect(接口请求日志切面)
...@@ -148,9 +147,8 @@ public class WebAspect extends BaseRequestAspect { ...@@ -148,9 +147,8 @@ public class WebAspect extends BaseRequestAspect {
* @throws Throwable * @throws Throwable
*/ */
private Object executeMethod(ProceedingJoinPoint joinPoint) throws Throwable { private Object executeMethod(ProceedingJoinPoint joinPoint) throws Throwable {
boolean dataArgs = joinPoint.getArgs().length != 1 List<Object> dataParas = this.getDataParameters(joinPoint.getArgs());
|| joinPoint.getArgs().length == 1 && boolean dataArgs = dataParas.isEmpty();
(joinPoint.getArgs()[0] instanceof ServletResponse || joinPoint.getArgs()[0] instanceof ServletRequest);
Method method = getMethod(joinPoint); Method method = getMethod(joinPoint);
boolean isUrl = false; boolean isUrl = false;
if (!StringHelper.isEmpty(reqUrl)) { if (!StringHelper.isEmpty(reqUrl)) {
...@@ -166,7 +164,7 @@ public class WebAspect extends BaseRequestAspect { ...@@ -166,7 +164,7 @@ public class WebAspect extends BaseRequestAspect {
return joinPoint.proceed(); return joinPoint.proceed();
} else { } else {
// 获取请求编号 // 获取请求编号
Object firstArgs = joinPoint.getArgs().length > 0 ? joinPoint.getArgs()[0] : null; Object firstArgs = dataParas.size() > 0 ? dataParas.get(0) : null;
String reqId = StringHelper.md5(JsonHelper.serialize(firstArgs)); String reqId = StringHelper.md5(JsonHelper.serialize(firstArgs));
String reqFull = StringHelper.getId(reqId, HttpAspectUtil.getHttpRequestUrl()); String reqFull = StringHelper.getId(reqId, HttpAspectUtil.getHttpRequestUrl());
RequestCacheResult req = cacheResult.get(reqFull, new RequestCacheResult(reqFull)); RequestCacheResult req = cacheResult.get(reqFull, new RequestCacheResult(reqFull));
......
...@@ -21,7 +21,7 @@ public class TokenServiceCall implements TokenLoad { ...@@ -21,7 +21,7 @@ public class TokenServiceCall implements TokenLoad {
private TokenService tokenService = null; private TokenService tokenService = null;
private int flagCount = 50; private int flagCount = 3;
public TokenServiceCall() { public TokenServiceCall() {
TokenHelper.setTokenLoad(this); TokenHelper.setTokenLoad(this);
......
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