Skip to content

Commit

Permalink
MARP-1548 Fix log missing arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
quanpham-axonivy committed Dec 19, 2024
1 parent c77e787 commit 3081427
Showing 1 changed file with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,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;
Expand All @@ -38,8 +41,9 @@ public void logMethodCall(JoinPoint joinPoint) throws MissingHeaderException {
ServletRequestAttributes attributes =
(ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
if (attributes != null) {
Method method = signature.getMethod();
HttpServletRequest request = attributes.getRequest();
Map<String, String> headersMap = extractHeaders(request, signature, joinPoint);
Map<String, String> headersMap = extractHeaders(request, method, joinPoint);
saveLogToDailyFile(headersMap);

// block execution if request isn't from Market or Ivy Designer
Expand All @@ -49,13 +53,16 @@ public void logMethodCall(JoinPoint joinPoint) throws MissingHeaderException {
}
}

private Map<String, String> extractHeaders(HttpServletRequest request, MethodSignature signature,
private Map<String, String> extractHeaders(HttpServletRequest request, Method method,
JoinPoint joinPoint) {
return Map.of(
LoggingConstants.METHOD, escapeXml(String.valueOf(signature.getMethod())),
LoggingConstants.METHOD, escapeXml(String.valueOf(method)),
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).toArray(String[]::new),
joinPoint.getArgs())),
CommonConstants.REQUESTED_BY, escapeXml(request.getHeader(CommonConstants.REQUESTED_BY))
);
}
Expand Down

0 comments on commit 3081427

Please sign in to comment.