diff --git a/mens-api/src/main/java/kr/xit/core/aop/TraceLoggerAspect.java b/mens-api/src/main/java/kr/xit/core/aop/TraceLoggerAspect.java index bd13fe9..9aa9138 100644 --- a/mens-api/src/main/java/kr/xit/core/aop/TraceLoggerAspect.java +++ b/mens-api/src/main/java/kr/xit/core/aop/TraceLoggerAspect.java @@ -8,10 +8,17 @@ import java.util.UUID; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; - import javax.servlet.http.HttpServletRequest; - +import kr.xit.core.biz.model.LoggingDTO; +import kr.xit.core.biz.service.ILoggingService; +import kr.xit.core.exception.BizRuntimeException; +import kr.xit.core.model.ApiResponseDTO; +import kr.xit.core.spring.util.error.ErrorParse; +import kr.xit.core.support.slack.SlackWebhookPush; +import kr.xit.core.support.utils.Checks; +import kr.xit.core.support.utils.JsonUtils; import kr.xit.core.support.utils.LogUtils; +import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.aspectj.lang.JoinPoint; import org.aspectj.lang.ProceedingJoinPoint; @@ -30,16 +37,6 @@ import org.springframework.stereotype.Component; import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.ServletRequestAttributes; -import kr.xit.core.exception.BizRuntimeException; -import kr.xit.core.model.ApiResponseDTO; -import kr.xit.core.biz.model.LoggingDTO; -import kr.xit.core.biz.service.ILoggingService; -import kr.xit.core.spring.util.error.ErrorParse; -import kr.xit.core.support.slack.SlackWebhookPush; -import kr.xit.core.support.utils.Checks; -import kr.xit.core.support.utils.JsonUtils; -import lombok.extern.slf4j.Slf4j; - /** *
* description : logging trace aspect @@ -126,7 +123,7 @@ public class TraceLoggerAspect { ServletRequestAttributes attributes = (ServletRequestAttributes)RequestContextHolder.getRequestAttributes(); HttpServletRequest request = attributes != null? attributes.getRequest(): null; - traceLogging(JsonUtils.toJson(pjp.getArgs()), request); + traceLogging(JsonUtils.toObjByObj(pjp.getArgs()[0], JSONObject.class), request); Object result = pjp.proceed(); if(result instanceof CompletableFuture){ @@ -163,7 +160,7 @@ public class TraceLoggerAspect { * @param params * @param request */ - protected void traceLogging(final String params, final HttpServletRequest request) { + protected void traceLogging(final JSONObject json, final HttpServletRequest request) { if(request != null) { String uri = request.getRequestURI(); if(Arrays.stream(excludes).anyMatch(uri::matches)) return; @@ -182,6 +179,7 @@ public class TraceLoggerAspect { } //TODO::systemId, reqSystemId 설정 필요 log.info("@@@@@@@@@@@@@@@@@로깅 start : [\n{}\n]",MDC.getCopyOfContextMap()); + String params = resetJsonMasking(json); MDC.put("systemId", "ENS"); MDC.put("reqSystemId", "KAKAO"); MDC.put("param", params); @@ -338,6 +336,7 @@ log.info("@@@@@@@@@@@@@@@@@로깅 start : [\n{}\n]",MDC.getCopyOfContextMap()); } private String maskingParam(final String key, final String value){ + if(Checks.isEmpty(value)) return value; if("juminId".equals(key)) { if(value.length() == 14) { return value.replaceAll("([0-9]{6})-([1-4]{1})([0-9]{6})", "$1-$2******"); @@ -358,4 +357,16 @@ log.info("@@@@@@@@@@@@@@@@@로깅 start : [\n{}\n]",MDC.getCopyOfContextMap()); } return value; } + + @SuppressWarnings("unchecked") + private String resetJsonMasking(final JSONObject json){ + for (Object key : json.keySet()) { + if(Checks.isEmpty(json.get(key))) { + json.put(key, json.get(key)); + }else { + json.put(key, maskingParam((String) key, String.valueOf(json.get(key)))); + } + } + return json.toJSONString(); + } }