Skip to content

Commit

Permalink
Merge pull request #119 from TEAM-DAWM/feat/118
Browse files Browse the repository at this point in the history
[feat] 이용자 ID 필드 추가 및 안쓰는 주석 삭제
  • Loading branch information
choyeongju authored Jul 19, 2024
2 parents ecac02a + 92ba64d commit 1f5be85
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import nutshell.server.discord.util.MDCUtil;
import nutshell.server.discord.model.EmbedObject;
import nutshell.server.discord.util.StringUtil;
import nutshell.server.exception.code.InternalServerErrorCode;

import java.awt.*;
import java.io.IOException;
Expand Down Expand Up @@ -74,6 +73,10 @@ protected void append(ILoggingEvent eventObject) {
"[" + MDCUtil.USER_IP_MDC + "]",
StringEscapeUtils.escapeJson(mdcPropertyMap.get(MDCUtil.USER_IP_MDC)),
false)
.addField(
"[" + MDCUtil.USER_INFO + "]",
StringEscapeUtils.escapeJson(mdcPropertyMap.get(MDCUtil.USER_INFO)),
false)
.addField(
"[" + MDCUtil.HEADER_MAP_MDC + "]",
StringEscapeUtils.escapeJson(mdcPropertyMap.get(MDCUtil.HEADER_MAP_MDC).replaceAll("[\\{\\{\\}]", "")),
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/nutshell/server/discord/filter/MDCFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import lombok.extern.slf4j.Slf4j;
import nutshell.server.discord.util.HttpRequestUtil;
import nutshell.server.discord.util.MDCUtil;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;
import org.springframework.web.filter.OncePerRequestFilter;
import org.springframework.web.util.WebUtils;
Expand All @@ -28,6 +29,7 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse

MDCUtil.setJsonValue(MDCUtil.REQUEST_URI_MDC, HttpRequestUtil.getRequestUri(Objects.requireNonNull(httpReq)));
MDCUtil.setJsonValue(MDCUtil.USER_IP_MDC, HttpRequestUtil.getUserIP(Objects.requireNonNull(httpReq)));
MDCUtil.setJsonValue(MDCUtil.USER_INFO, SecurityContextHolder.getContext().getAuthentication().getPrincipal());
MDCUtil.setJsonValue(MDCUtil.HEADER_MAP_MDC, HttpRequestUtil.getHeaderMap(httpReq));
MDCUtil.setJsonValue(MDCUtil.PARAMETER_MAP_MDC, HttpRequestUtil.getParamMap(httpReq));
MDCUtil.setJsonValue(MDCUtil.BODY_MDC, HttpRequestUtil.getBody(httpReq));
Expand Down
9 changes: 1 addition & 8 deletions src/main/java/nutshell/server/discord/util/MDCUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,13 @@ public class MDCUtil {

public static final String REQUEST_URI_MDC = "이용자 요청 URI 정보";
public static final String USER_IP_MDC = "이용자 IP 정보";
public static final String USER_INFO = "이용자 ID 정보";
public static final String HEADER_MAP_MDC = "HTTP 헤더 정보";
public static final String PARAMETER_MAP_MDC = "Parameter 정보";
public static final String BODY_MDC = "HTTP Body 정보";
private static final ObjectMapper objectMapper = new ObjectMapper();
private static final MDCAdapter mdc = MDC.getMDCAdapter();

public static void set(String key, String value) {
mdc.put(key, value);
}

public static void setJsonValue(String key, Object value) throws JsonProcessingException {
try {
if (value != null) {
Expand All @@ -35,8 +32,4 @@ public static void setJsonValue(String key, Object value) throws JsonProcessingE
throw ex;
}
}

public static void clear() {
MDC.clear();
}
}

0 comments on commit 1f5be85

Please sign in to comment.