From 77fadf447cb8570ecf1507d3c236cef823ccd06a Mon Sep 17 00:00:00 2001 From: "AAVN\\pvquan" Date: Thu, 19 Dec 2024 14:18:24 +0700 Subject: [PATCH] test --- .../axonivy/market/logging/LoggableAspect.java | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/marketplace-service/src/main/java/com/axonivy/market/logging/LoggableAspect.java b/marketplace-service/src/main/java/com/axonivy/market/logging/LoggableAspect.java index 059a1998..57320607 100644 --- a/marketplace-service/src/main/java/com/axonivy/market/logging/LoggableAspect.java +++ b/marketplace-service/src/main/java/com/axonivy/market/logging/LoggableAspect.java @@ -6,6 +6,7 @@ import jakarta.servlet.http.HttpServletRequest; import lombok.extern.log4j.Log4j2; import org.aspectj.lang.JoinPoint; +import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; import org.aspectj.lang.reflect.MethodSignature; @@ -16,8 +17,11 @@ import java.io.File; import java.io.IOException; +import java.lang.reflect.Method; +import java.lang.reflect.Parameter; import java.nio.file.Files; import java.nio.file.Path; +import java.util.Arrays; import java.util.Map; import static com.axonivy.market.util.FileUtils.createFile; @@ -38,8 +42,11 @@ public void logMethodCall(JoinPoint joinPoint) throws MissingHeaderException { ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); if (attributes != null) { + Method method = signature.getMethod(); + log.debug("#extractHeaders arguments {} ---- {}", method.getParameters(), joinPoint.getArgs()); + log.info("#extractHeaders arguments {} ---- {}", method.getParameters(), joinPoint.getArgs()); HttpServletRequest request = attributes.getRequest(); - Map headersMap = extractHeaders(request, signature, joinPoint); + Map headersMap = extractHeaders(request, method, joinPoint); saveLogToDailyFile(headersMap); // block execution if request isn't from Market or Ivy Designer @@ -49,13 +56,16 @@ public void logMethodCall(JoinPoint joinPoint) throws MissingHeaderException { } } - private Map extractHeaders(HttpServletRequest request, MethodSignature signature, + private Map extractHeaders(HttpServletRequest request, Method method, JoinPoint joinPoint) { return Map.of( - LoggingConstants.METHOD, escapeXml(String.valueOf(signature.getMethod())), + LoggingConstants.METHOD, escapeXml(method.getName()), LoggingConstants.TIMESTAMP, escapeXml(getCurrentTimestamp()), CommonConstants.USER_AGENT, escapeXml(request.getHeader(CommonConstants.USER_AGENT)), - LoggingConstants.ARGUMENTS, escapeXml(getArgumentsString(signature.getParameterNames(), joinPoint.getArgs())), + LoggingConstants.ARGUMENTS, + escapeXml(getArgumentsString( + Arrays.stream(method.getParameters()).map(Parameter::getName).toList().toArray(new String[0]), + joinPoint.getArgs())), CommonConstants.REQUESTED_BY, escapeXml(request.getHeader(CommonConstants.REQUESTED_BY)) ); }