新增系统日志记录开启

This commit is contained in:
wenc000 2020-05-08 19:33:17 +08:00
parent eaad8bf31e
commit 626a4e320c

View File

@ -16,6 +16,7 @@ import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut; import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.annotation.Order; import org.springframework.core.annotation.Order;
import org.springframework.core.io.InputStreamSource; import org.springframework.core.io.InputStreamSource;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -39,6 +40,8 @@ public class ApiLogAspect {
private SecurityComponent securityComponent; private SecurityComponent securityComponent;
@Autowired @Autowired
private ISystemLoggerService systemLoggerService; private ISystemLoggerService systemLoggerService;
@Value("${logging.enable-syslog:false}")
private Boolean enableSyslog;
/** /**
* api切入点 * api切入点
@ -49,6 +52,9 @@ public class ApiLogAspect {
@Around("apiCutPoint()") @Around("apiCutPoint()")
public Object apiLogAround(ProceedingJoinPoint proceedingJoinPoint) throws Throwable { public Object apiLogAround(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
if (enableSyslog == null || !enableSyslog) {
return proceedingJoinPoint.proceed();
}
return logAroundForApi(proceedingJoinPoint); return logAroundForApi(proceedingJoinPoint);
} }
@ -61,6 +67,9 @@ public class ApiLogAspect {
@Around("resourceCutPoint()") @Around("resourceCutPoint()")
public Object resourcesLogAround(ProceedingJoinPoint proceedingJoinPoint) throws Throwable { public Object resourcesLogAround(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
if (enableSyslog == null || !enableSyslog) {
return proceedingJoinPoint.proceed();
}
return logAroundForResource(proceedingJoinPoint); return logAroundForResource(proceedingJoinPoint);
} }
@ -73,6 +82,9 @@ public class ApiLogAspect {
@Around("appCutPoint()") @Around("appCutPoint()")
public Object appLogAround(ProceedingJoinPoint proceedingJoinPoint) throws Throwable { public Object appLogAround(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
if (enableSyslog == null || !enableSyslog) {
return proceedingJoinPoint.proceed();
}
return logAroundForApp(proceedingJoinPoint); return logAroundForApp(proceedingJoinPoint);
} }
@ -164,7 +176,7 @@ public class ApiLogAspect {
systemLoggerVO.setStartTime(startTime); systemLoggerVO.setStartTime(startTime);
systemLoggerVO.setEndTime(endTime); systemLoggerVO.setEndTime(endTime);
systemLoggerVO.setUsedTime(usedTime); systemLoggerVO.setUsedTime(usedTime);
systemLoggerVO.setResponseResult(result == null ? "null" : JSON.toJSONString(result)); // systemLoggerVO.setResponseResult(result == null ? "null" : JSON.toJSONString(result));
Map<String, Object> params = WMapUtil.beanToMapObj(systemLoggerVO); Map<String, Object> params = WMapUtil.beanToMapObj(systemLoggerVO);
params.put("systemLoggerId", UUIDUtil.getUUID()); params.put("systemLoggerId", UUIDUtil.getUUID());
params.put("gmtCreate", currentTime); params.put("gmtCreate", currentTime);
@ -203,7 +215,7 @@ public class ApiLogAspect {
systemLoggerVO.setStartTime(startTime); systemLoggerVO.setStartTime(startTime);
systemLoggerVO.setEndTime(endTime); systemLoggerVO.setEndTime(endTime);
systemLoggerVO.setUsedTime(usedTime); systemLoggerVO.setUsedTime(usedTime);
systemLoggerVO.setResponseResult(result == null ? "null" : JSON.toJSONString(result)); // systemLoggerVO.setResponseResult(result == null ? "null" : JSON.toJSONString(result));
Map<String, Object> params = WMapUtil.beanToMapObj(systemLoggerVO); Map<String, Object> params = WMapUtil.beanToMapObj(systemLoggerVO);
params.put("systemLoggerId", UUIDUtil.getUUID()); params.put("systemLoggerId", UUIDUtil.getUUID());
params.put("gmtCreate", currentTime); params.put("gmtCreate", currentTime);