Commit 0ed3022a authored by yanzg's avatar yanzg

修复等待时间

parent 2617307d
...@@ -3,7 +3,7 @@ package com.yanzuoguang.util.base; ...@@ -3,7 +3,7 @@ package com.yanzuoguang.util.base;
import com.yanzuoguang.util.helper.StringHelper; import com.yanzuoguang.util.helper.StringHelper;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
/** /**
...@@ -26,7 +26,7 @@ public class CollectionString { ...@@ -26,7 +26,7 @@ public class CollectionString {
*/ */
public static <T> String getCollectionString(String tag, Collection<T> rowList) { public static <T> String getCollectionString(String tag, Collection<T> rowList) {
// 每个字段的长度 // 每个字段的长度
Map<String, Integer> mapFieldCount = new HashMap<>(15); Map<String, Integer> mapFieldCount = new LinkedHashMap<>(15);
// 每个值的长度 // 每个值的长度
rowList.forEach(k -> ObjectEach.each(k, (name, value, field) -> { rowList.forEach(k -> ObjectEach.each(k, (name, value, field) -> {
// 获取字符串 // 获取字符串
......
...@@ -18,15 +18,13 @@ import org.springframework.stereotype.Component; ...@@ -18,15 +18,13 @@ import org.springframework.stereotype.Component;
@Component @Component
public class AspectLogResult { public class AspectLogResult {
public static final int WAIT_MAX = 30;
public static final int WAIT_ITEM = 10;
private final CloudConfig cloudConfig; private final CloudConfig cloudConfig;
private final LogLocal logLocal; private final LogLocal logLocal;
private final AspectLogBody aspectLogBody; private final AspectLogBody aspectLogBody;
private final AspectLogTime aspectLogTime; private final AspectLogTime aspectLogTime;
private final ResponseResult<Object> responseDefault = new ResponseResult(); private final ResponseResult<String> responseDefault = ResponseResult.result("操作成功");
public AspectLogResult(CloudConfig cloudConfig, LogLocal logLocal, AspectLogBody aspectLogBody, AspectLogTime aspectLogTime) { public AspectLogResult(CloudConfig cloudConfig, LogLocal logLocal, AspectLogBody aspectLogBody, AspectLogTime aspectLogTime) {
this.cloudConfig = cloudConfig; this.cloudConfig = cloudConfig;
...@@ -52,39 +50,41 @@ public class AspectLogResult { ...@@ -52,39 +50,41 @@ public class AspectLogResult {
public void responseLog(Class<?> cls, String tag, String url, boolean logFlag, long start, public void responseLog(Class<?> cls, String tag, String url, boolean logFlag, long start,
Object requestBody, Object result, Exception resultEx, LogVo log) { Object requestBody, Object result, Exception resultEx, LogVo log) {
try { try {
// 执行时间
long time = System.currentTimeMillis() - start;
// 全路径
String fullUrl = String.format("%s:%s", tag, url); String fullUrl = String.format("%s:%s", tag, url);
// 输出日志标记
// ThreadHelper.waitRun(WAIT_MAX, WAIT_ITEM, k -> StringHelper.isEmpty(log.getLogId())); boolean isLogCommon = logFlag && this.cloudConfig.isLogCommon();
if (StringHelper.isEmpty(log.getLogId())) { boolean isLogDatabase = resultEx != null;
boolean isLogDisplay = isLogCommon || isLogDatabase;
// 记录请求时间
aspectLogTime.finish(fullUrl, time, isLogDatabase);
// ThreadHelper.waitRun(WAIT_MAX, WAIT_ITEM, k -> StringHelper.isEmpty(log.getLogId()))
if (StringHelper.isEmpty(log.getLogId()) || !isLogDisplay) {
return; return;
} }
String body = aspectLogBody.getBodyString(requestBody); String body = aspectLogBody.getBodyString(requestBody);
if (!StringHelper.compare(log.getContent(), body)) { if (!StringHelper.compare(log.getContent(), body)) {
log.setContentTo(body); log.setContentTo(body);
} }
long time = System.currentTimeMillis() - start;
boolean isLogCommon = logFlag && this.cloudConfig.isLogCommon();
boolean isLogDatabase = resultEx != null;
boolean isLogDisplay = isLogCommon || isLogDatabase;
// 处理结果 // 处理结果
ResponseResult responseResult = responseDefault; ResponseResult<?> responseResult;
if (result instanceof ResponseResult) { if (result instanceof ResponseResult) {
responseResult = (ResponseResult) result; responseResult = (ResponseResult<?>) result;
} else if (result != null) { } else if (result != null) {
responseResult = ResponseResult.result(result); responseResult = ResponseResult.result(result);
} else if (resultEx != null) {
responseResult = ExceptionHelper.getError(resultEx);
} else {
responseResult = responseDefault;
} }
if (isLogDisplay) {
// 执行时间 String json = JsonHelper.serialize(responseResult);
if (resultEx != null) { Log.error(cls, resultEx, "%s [ %s ] time %d ms, result: %s", tag, url, time, aspectLogBody.getMaxString(json));
responseResult = ExceptionHelper.getError(resultEx); if (isLogDatabase) {
} logLocal.result(log, responseResult.getCode(), json);
String json = JsonHelper.serialize(responseResult);
Log.error(cls, resultEx, "%s [ %s ] time %d ms, result: %s", tag, url, time, aspectLogBody.getMaxString(json));
if (isLogDatabase) {
logLocal.result(log, responseResult.getCode(), json);
}
} }
aspectLogTime.finish(fullUrl, time, isLogDatabase);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
......
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