Commit 93255d30 authored by yanzg's avatar yanzg

不记录系统日志

parent ce382c60
...@@ -164,17 +164,18 @@ public class BaseRequestAspect { ...@@ -164,17 +164,18 @@ public class BaseRequestAspect {
/** /**
* 记录请求日志 * 记录请求日志
* *
* @param joinPoint * @param tag
* @param url
* @param requestBody
* @param logFlag
* @return * @return
*/ */
protected long requestLog(String tag, boolean logFlag, ProceedingJoinPoint joinPoint) { protected long requestLog(Class<?> cls, String tag, String url, String requestBody, boolean logFlag) {
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
try { try {
boolean isLog = logFlag && logCommon; boolean isLog = logFlag && logCommon;
if (isLog) { if (isLog) {
String name = joinPoint.getSignature().getName(); Log.info(cls, " %s [ %s ] request: %s", tag, url, this.getMaxString(requestBody));
Log.info(joinPoint.getSignature().getDeclaringType(), " %s [ %s ] request: %s",
tag, name, this.getMaxString(JsonHelper.serialize(getFirstDataParameter(joinPoint.getArgs()))));
} }
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
...@@ -185,17 +186,20 @@ public class BaseRequestAspect { ...@@ -185,17 +186,20 @@ public class BaseRequestAspect {
/** /**
* 保存日志 * 保存日志
* *
* @param joinPoint * @param cls
* @param tag
* @param url
* @param logFlag
* @param start
* @param result * @param result
* @param resultEx * @param resultEx
* @param start * @param log
*/ */
protected void responseLog(LogVo log, String tag, String url, boolean logFlag, ProceedingJoinPoint joinPoint, long start, Object result, Exception resultEx) { protected void responseLog(Class<?> cls, String tag, String url, boolean logFlag, long start, Object result, Exception resultEx, LogVo log) {
try { try {
long time = System.currentTimeMillis() - start; long time = System.currentTimeMillis() - start;
boolean isLogDisplay = (logFlag && logCommon) || resultEx != null; boolean isLogDisplay = (logFlag && logCommon) || resultEx != null;
boolean isLogDatabase = log != null || resultEx != null; boolean isLogDatabase = log != null || resultEx != null;
String name = joinPoint.getSignature().getName();
// 处理结果 // 处理结果
ResponseResult responseResult = responseDefault; ResponseResult responseResult = responseDefault;
if (result instanceof ResponseResult) { if (result instanceof ResponseResult) {
...@@ -208,12 +212,14 @@ public class BaseRequestAspect { ...@@ -208,12 +212,14 @@ public class BaseRequestAspect {
responseResult = ExceptionHelper.getError(resultEx); responseResult = ExceptionHelper.getError(resultEx);
resultEx.printStackTrace(); resultEx.printStackTrace();
} }
if (isLogDisplay) { if (isLogDisplay || isLogDatabase) {
Log.error(joinPoint.getSignature().getDeclaringType(), resultEx, "%s [ %s ] time %d ms, result: %s", String json = JsonHelper.serialize(responseResult);
tag, name, time, getMaxString(JsonHelper.serialize(responseResult))); if (isLogDisplay) {
} Log.error(cls, resultEx, "%s [ %s ] time %d ms, result: %s", tag, url, time, getMaxString(json));
if (isLogDatabase) { }
logLocal.result(log, name, responseResult.getCode(), JsonHelper.serialize(responseResult)); if (isLogDatabase) {
logLocal.result(log, tag, responseResult.getCode(), json);
}
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
......
...@@ -70,19 +70,15 @@ public class WebAspect extends BaseRequestAspect { ...@@ -70,19 +70,15 @@ public class WebAspect extends BaseRequestAspect {
result = executeMethod(joinPoint); result = executeMethod(joinPoint);
return result; return result;
} }
Class declaringType = joinPoint.getSignature().getDeclaringType();
String url = getMethodUrl(joinPoint);
String requestBody = getRequestBody(joinPoint);
LogVo log = null; LogVo log = null;
boolean clear = requestLogInit(); boolean clear = requestLogInit();
long start = System.currentTimeMillis(); long start = requestLog(declaringType, TAG, url, requestBody, clear);
String url = getMethodUrl(joinPoint);
if (clear) { if (clear) {
log = startLog(TAG, url, getRequestBody(joinPoint)); log = startLog(TAG, url, requestBody);
clear = clear && log != null;
} }
if (clear) {
Log.threadBegin();
start = requestLog(TAG, clear, joinPoint);
}
Exception ex = null; Exception ex = null;
boolean isInit = false; boolean isInit = false;
try { try {
...@@ -124,7 +120,7 @@ public class WebAspect extends BaseRequestAspect { ...@@ -124,7 +120,7 @@ public class WebAspect extends BaseRequestAspect {
if (isInit) { if (isInit) {
TokenHelper.remove(); TokenHelper.remove();
} }
responseLog(log, TAG, url, clear, joinPoint, start, result, ex); responseLog(declaringType, TAG, url, clear, start, result, ex, log);
} }
} }
...@@ -134,7 +130,7 @@ public class WebAspect extends BaseRequestAspect { ...@@ -134,7 +130,7 @@ public class WebAspect extends BaseRequestAspect {
* @return * @return
*/ */
private boolean isGateWay() { private boolean isGateWay() {
return this.applicationName.matches(this.gateWay); return this.applicationName.toLowerCase().matches(this.gateWay);
} }
......
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