Skip to content

Commit

Permalink
[FIX] exceptionBrief가 183이 넘을 경우 substring으로 잘라서 전달하도록 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
sung-silver committed Jan 18, 2024
1 parent c9c1d99 commit 24555af
Showing 1 changed file with 8 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
import com.nonsoolmate.nonsoolmateServer.global.util.StringUtil;
import io.micrometer.core.instrument.util.StringEscapeUtils;
import com.nonsoolmate.nonsoolmateServer.external.discord.model.EmbedObject;

import java.awt.Color;
import java.io.IOException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Map;

import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

Expand Down Expand Up @@ -59,52 +61,16 @@ protected void append(ILoggingEvent eventObject) {
exceptionBrief = "EXCEPTION 정보가 남지 않았습니다.";
}

discordWebhook.addEmbed(new EmbedObject()
.setTitle("[" + level + " - 문제 간략 내용]")
.setColor(messageColor)
.setDescription(exceptionBrief)
.addField("[" + "Exception Level" + "]",
StringEscapeUtils.escapeJson(level),
true)
.addField("[문제 발생 시각]",
LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")),
false)
.addField(
"[" + MDCUtil.REQUEST_URI_MDC + "]",
StringEscapeUtils.escapeJson(mdcPropertyMap.get(MDCUtil.REQUEST_URI_MDC)),
false)
.addField(
"[" + MDCUtil.USER_IP_MDC + "]",
StringEscapeUtils.escapeJson(mdcPropertyMap.get(MDCUtil.USER_IP_MDC)),
false)
.addField(
"[" + MDCUtil.HEADER_MAP_MDC + "]",
StringEscapeUtils.escapeJson(mdcPropertyMap.get(MDCUtil.HEADER_MAP_MDC).replaceAll("[\\{\\{\\}]", "")),
true)
.addField(
"[" + MDCUtil.USER_REQUEST_COOKIES + "]",
StringEscapeUtils.escapeJson(
mdcPropertyMap.get(MDCUtil.USER_REQUEST_COOKIES).replaceAll("[\\{\\{\\}]", "")),
false)
.addField(
"[" + MDCUtil.PARAMETER_MAP_MDC + "]",
StringEscapeUtils.escapeJson(
mdcPropertyMap.get(MDCUtil.PARAMETER_MAP_MDC).replaceAll("[\\{\\{\\}]", "")),
false)
.addField("[" + MDCUtil.BODY_MDC + "]",
StringEscapeUtils.escapeJson(StringUtil.translateEscapes(mdcPropertyMap.get(MDCUtil.BODY_MDC))),
false)
);
if (exceptionBrief.length() > 183) {
exceptionBrief = exceptionBrief.substring(0, 183);
}

discordWebhook.addEmbed(new EmbedObject().setTitle("[" + level + " - 문제 간략 내용]").setColor(messageColor).setDescription(exceptionBrief).addField("[" + "Exception Level" + "]", StringEscapeUtils.escapeJson(level), true).addField("[문제 발생 시각]", LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")), false).addField("[" + MDCUtil.REQUEST_URI_MDC + "]", StringEscapeUtils.escapeJson(mdcPropertyMap.get(MDCUtil.REQUEST_URI_MDC)), false).addField("[" + MDCUtil.USER_IP_MDC + "]", StringEscapeUtils.escapeJson(mdcPropertyMap.get(MDCUtil.USER_IP_MDC)), false).addField("[" + MDCUtil.HEADER_MAP_MDC + "]", StringEscapeUtils.escapeJson(mdcPropertyMap.get(MDCUtil.HEADER_MAP_MDC).replaceAll("[\\{\\{\\}]", "")), true).addField("[" + MDCUtil.USER_REQUEST_COOKIES + "]", StringEscapeUtils.escapeJson(mdcPropertyMap.get(MDCUtil.USER_REQUEST_COOKIES).replaceAll("[\\{\\{\\}]", "")), false).addField("[" + MDCUtil.PARAMETER_MAP_MDC + "]", StringEscapeUtils.escapeJson(mdcPropertyMap.get(MDCUtil.PARAMETER_MAP_MDC).replaceAll("[\\{\\{\\}]", "")), false).addField("[" + MDCUtil.BODY_MDC + "]", StringEscapeUtils.escapeJson(StringUtil.translateEscapes(mdcPropertyMap.get(MDCUtil.BODY_MDC))), false));

if (throwable != null) {
exceptionDetail = ThrowableProxyUtil.asString(throwable);
String exception = exceptionDetail.substring(0, 4000);
discordWebhook.addEmbed(
new EmbedObject()
.setTitle("[Exception 상세 내용]")
.setColor(messageColor)
.setDescription(StringEscapeUtils.escapeJson(exception))
);
discordWebhook.addEmbed(new EmbedObject().setTitle("[Exception 상세 내용]").setColor(messageColor).setDescription(StringEscapeUtils.escapeJson(exception)));
}

try {
Expand Down

0 comments on commit 24555af

Please sign in to comment.