|
|
|
@ -65,6 +65,15 @@ public class AccessLogAspect {
|
|
|
|
|
public Object doAround(ProceedingJoinPoint proceedingJoinPoint) throws Throwable { |
|
|
|
|
long startTime = System.currentTimeMillis(); |
|
|
|
|
|
|
|
|
|
String URI = null; |
|
|
|
|
String requestMethod = null; |
|
|
|
|
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); |
|
|
|
|
if (attributes != null) { |
|
|
|
|
HttpServletRequest request = attributes.getRequest(); |
|
|
|
|
URI = request.getRequestURI(); |
|
|
|
|
requestMethod = request.getMethod(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// fetch AccessLogAnnotation
|
|
|
|
|
MethodSignature sign = (MethodSignature) proceedingJoinPoint.getSignature(); |
|
|
|
|
Method method = sign.getMethod(); |
|
|
|
@ -74,12 +83,10 @@ public class AccessLogAspect {
|
|
|
|
|
|
|
|
|
|
// log request
|
|
|
|
|
if (!annotation.ignoreRequest()) { |
|
|
|
|
ServletRequestAttributes attributes = |
|
|
|
|
(ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); |
|
|
|
|
if (attributes != null) { |
|
|
|
|
HttpServletRequest request = attributes.getRequest(); |
|
|
|
|
String traceIdFromHeader = request.getHeader(TRACE_ID); |
|
|
|
|
if (!StringUtils.isEmpty(traceIdFromHeader)) { |
|
|
|
|
if (StringUtils.isNotEmpty(traceIdFromHeader)) { |
|
|
|
|
traceId = traceIdFromHeader; |
|
|
|
|
} |
|
|
|
|
// handle login info
|
|
|
|
@ -103,11 +110,7 @@ public class AccessLogAspect {
|
|
|
|
|
|
|
|
|
|
Object ob = proceedingJoinPoint.proceed(); |
|
|
|
|
|
|
|
|
|
// log response
|
|
|
|
|
if (!annotation.ignoreResponse()) { |
|
|
|
|
log.info("RESPONSE TRACE_ID:{}, BODY:{}, REQUEST DURATION:{} milliseconds", traceId, ob, |
|
|
|
|
(System.currentTimeMillis() - startTime)); |
|
|
|
|
} |
|
|
|
|
log.info("Call {}:{} success, cost: {}ms", requestMethod, URI, (System.currentTimeMillis() - startTime)); |
|
|
|
|
|
|
|
|
|
return ob; |
|
|
|
|
} |
|
|
|
|