diff --git a/hcframe-parent/hcframe-base/src/main/java/com/taixingyiji/base/module/log/RequestLogAspect.java b/hcframe-parent/hcframe-base/src/main/java/com/taixingyiji/base/module/log/RequestLogAspect.java index fff4a6a..382cd65 100644 --- a/hcframe-parent/hcframe-base/src/main/java/com/taixingyiji/base/module/log/RequestLogAspect.java +++ b/hcframe-parent/hcframe-base/src/main/java/com/taixingyiji/base/module/log/RequestLogAspect.java @@ -45,38 +45,42 @@ public class RequestLogAspect { public Object doAround(ProceedingJoinPoint proceedingJoinPoint) throws Throwable { long start = System.currentTimeMillis(); - ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); - HttpServletRequest request = attributes.getRequest(); Object result = proceedingJoinPoint.proceed(); - - if (frameConfig.getShowControllerLog()) { - RequestInfo requestInfo = new RequestInfo(); - requestInfo.setIp(request.getRemoteAddr()); - requestInfo.setUrl(request.getRequestURL().toString()); - requestInfo.setHttpMethod(request.getMethod()); - requestInfo.setClassMethod(String.format("%s.%s", proceedingJoinPoint.getSignature().getDeclaringTypeName(), - proceedingJoinPoint.getSignature().getName())); - requestInfo.setRequestParams(getRequestParamsByProceedingJoinPoint(proceedingJoinPoint)); - requestInfo.setResult(result); - requestInfo.setTimeCost(System.currentTimeMillis() - start); - LOGGER.info("Request Info : {}", JSON.toJSONString(requestInfo)); + ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); + if (attributes != null) { + HttpServletRequest request = attributes.getRequest(); + if (frameConfig.getShowControllerLog()) { + RequestInfo requestInfo = new RequestInfo(); + requestInfo.setIp(request.getRemoteAddr()); + requestInfo.setUrl(request.getRequestURL().toString()); + requestInfo.setHttpMethod(request.getMethod()); + requestInfo.setClassMethod(String.format("%s.%s", proceedingJoinPoint.getSignature().getDeclaringTypeName(), + proceedingJoinPoint.getSignature().getName())); + requestInfo.setRequestParams(getRequestParamsByProceedingJoinPoint(proceedingJoinPoint)); + requestInfo.setResult(result); + requestInfo.setTimeCost(System.currentTimeMillis() - start); + LOGGER.info("Request Info : {}", JSON.toJSONString(requestInfo)); + } } + return result; } @AfterThrowing(pointcut = "requestServer()", throwing = "e") public void doAfterThrow(JoinPoint joinPoint, RuntimeException e) { ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); - HttpServletRequest request = attributes.getRequest(); - RequestErrorInfo requestErrorInfo = new RequestErrorInfo(); - requestErrorInfo.setIp(request.getRemoteAddr()); - requestErrorInfo.setUrl(request.getRequestURL().toString()); - requestErrorInfo.setHttpMethod(request.getMethod()); - requestErrorInfo.setClassMethod(String.format("%s.%s", joinPoint.getSignature().getDeclaringTypeName(), - joinPoint.getSignature().getName())); - requestErrorInfo.setRequestParams(getRequestParamsByJoinPoint(joinPoint)); - requestErrorInfo.setException(e); - LOGGER.error("Error Request Info : {}", JSON.toJSONString(requestErrorInfo)); + if (attributes != null) { + HttpServletRequest request = attributes.getRequest(); + RequestErrorInfo requestErrorInfo = new RequestErrorInfo(); + requestErrorInfo.setIp(request.getRemoteAddr()); + requestErrorInfo.setUrl(request.getRequestURL().toString()); + requestErrorInfo.setHttpMethod(request.getMethod()); + requestErrorInfo.setClassMethod(String.format("%s.%s", joinPoint.getSignature().getDeclaringTypeName(), + joinPoint.getSignature().getName())); + requestErrorInfo.setRequestParams(getRequestParamsByJoinPoint(joinPoint)); + requestErrorInfo.setException(e); + LOGGER.error("Error Request Info : {}", JSON.toJSONString(requestErrorInfo)); + } } /** diff --git a/hcframe-parent/pom.xml b/hcframe-parent/pom.xml index 0851d43..d46fffb 100644 --- a/hcframe-parent/pom.xml +++ b/hcframe-parent/pom.xml @@ -230,25 +230,25 @@ - - releases - Releases - http://192.168.0.123:8081/repository/maven-releases/ - - - snapshots - Snapshot - http://192.168.0.123:8081/repository/maven-snapshots/ - - + - + - + - + + + releases-hc + Releases + https://qs.taixingyiji.com:8082/repository/maven-releases/ + + + snapshots-hc + Snapshot + https://qs.taixingyiji.com:8082/repository/maven-snapshots/ +