From 36c9d3c91a67390e352265ddbff4175ae07df398 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EB=8F=99=ED=9B=88?= <2dh2@naver.com> Date: Sat, 27 Dec 2025 22:00:14 +0900 Subject: [PATCH 1/2] =?UTF-8?q?refactor:=20MDC=20=EC=A0=9C=EA=B1=B0,=20Log?= =?UTF-8?q?ger=EB=A1=9C=20=EC=97=90=EB=9F=AC=20=EC=8B=9C=EC=A0=90=20?= =?UTF-8?q?=EA=B5=AC=EB=B6=84=ED=95=A0=20=EC=88=98=20=EC=9E=88=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exception/GlobalExceptionHandler.java | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/main/java/gg/agit/konect/global/exception/GlobalExceptionHandler.java b/src/main/java/gg/agit/konect/global/exception/GlobalExceptionHandler.java index 26377ff3..5c48b57f 100644 --- a/src/main/java/gg/agit/konect/global/exception/GlobalExceptionHandler.java +++ b/src/main/java/gg/agit/konect/global/exception/GlobalExceptionHandler.java @@ -9,7 +9,8 @@ import java.util.UUID; import org.apache.catalina.connector.ClientAbortException; -import org.slf4j.MDC; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatusCode; import org.springframework.http.ResponseEntity; @@ -29,7 +30,6 @@ import org.springframework.web.util.WebUtils; import gg.agit.konect.global.code.ApiResponseCode; - import jakarta.servlet.http.HttpServletRequest; import lombok.extern.slf4j.Slf4j; @@ -37,6 +37,8 @@ @RestControllerAdvice public class GlobalExceptionHandler extends ResponseEntityExceptionHandler { + private static final Logger RUNTIME_ERROR_LOGGER = LoggerFactory.getLogger("runtime.error"); + @ExceptionHandler(CustomException.class) public ResponseEntity handleCustomException( HttpServletRequest request, @@ -147,20 +149,21 @@ public ResponseEntity handleException(HttpServletRequest request, Except StackTraceElement origin = e.getStackTrace()[0]; String uri = String.format("%s %s", request.getMethod(), request.getRequestURI()); - String location = String.format( - "%s:%d", - origin.getFileName(), - origin.getLineNumber() - ); String exception = e.getClass().getSimpleName(); + String location = String.format("%s:%d", origin.getFileName(), origin.getLineNumber()); String message = e.getMessage(); - MDC.put("uri", uri); - MDC.put("location", location); - MDC.put("exception", exception); - MDC.put("message", message); + String slackMessage = String.format( + """ + URI: `%s` + Location: `%s` + Exception: `%s` + ```%s``` + """, + uri, location, exception, message + ); - log.error("URI: {} | Location: {} | Exception: {} | Message: {}", uri, location, exception, message); + RUNTIME_ERROR_LOGGER.error(slackMessage); return buildErrorResponse(ApiResponseCode.UNEXPECTED_SERVER_ERROR); } From 4a9f01a9a23245b7dc27b57813e15d9c15d172b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EB=8F=99=ED=9B=88?= <2dh2@naver.com> Date: Sat, 27 Dec 2025 22:00:38 +0900 Subject: [PATCH 2/2] =?UTF-8?q?refactor:=20=EC=95=A0=ED=94=8C=EB=A6=AC?= =?UTF-8?q?=EC=BC=80=EC=9D=B4=EC=85=98=20=EC=8B=A4=ED=96=89=20=EC=8B=9C?= =?UTF-8?q?=EC=A0=90=EC=97=90=20=EB=8C=80=ED=95=9C=20=EC=97=90=EB=9F=AC=20?= =?UTF-8?q?=EC=95=8C=EB=A6=BC=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/logback-spring.xml | 33 ++++++++++++++++++++------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/src/main/resources/logback-spring.xml b/src/main/resources/logback-spring.xml index 181225bf..c0c4d09f 100644 --- a/src/main/resources/logback-spring.xml +++ b/src/main/resources/logback-spring.xml @@ -13,18 +13,31 @@ - + ${SLACK_WEBHOOK_ERROR} true + + + + ${SLACK_WEBHOOK_ERROR} + + + + true + + + + ERROR ACCEPT @@ -32,8 +45,8 @@ Exception: `%mdc{exception}`%n - - + + ERROR ACCEPT @@ -41,8 +54,12 @@ Exception: `%mdc{exception}`%n + + + + - +