diff --git a/src/main/java/nutshell/server/discord/external/DiscordAppender.java b/src/main/java/nutshell/server/discord/external/DiscordAppender.java index c0eeeac..942c879 100644 --- a/src/main/java/nutshell/server/discord/external/DiscordAppender.java +++ b/src/main/java/nutshell/server/discord/external/DiscordAppender.java @@ -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; @@ -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("[\\{\\{\\}]", "")), diff --git a/src/main/java/nutshell/server/discord/filter/MDCFilter.java b/src/main/java/nutshell/server/discord/filter/MDCFilter.java index 27f5bc6..9539790 100644 --- a/src/main/java/nutshell/server/discord/filter/MDCFilter.java +++ b/src/main/java/nutshell/server/discord/filter/MDCFilter.java @@ -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; @@ -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)); diff --git a/src/main/java/nutshell/server/discord/util/MDCUtil.java b/src/main/java/nutshell/server/discord/util/MDCUtil.java index 2c5099c..a092e78 100644 --- a/src/main/java/nutshell/server/discord/util/MDCUtil.java +++ b/src/main/java/nutshell/server/discord/util/MDCUtil.java @@ -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) { @@ -35,8 +32,4 @@ public static void setJsonValue(String key, Object value) throws JsonProcessingE throw ex; } } - - public static void clear() { - MDC.clear(); - } }