From e1f21246e346a23a4bcd0a4bca1ec76f6358f7de Mon Sep 17 00:00:00 2001 From: haeyonghahn Date: Sat, 9 Mar 2024 02:05:11 +0900 Subject: [PATCH] =?UTF-8?q?Feat:=20=EB=A1=9C=EA=B7=B8=20=EA=B8=B0=EB=A1=9D?= =?UTF-8?q?=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 로그 포맷 수정 - 진입점 추가 Resolves: feat/#56 --- build.gradle | 2 + ...ceptor.java => MDCLoggingInterceptor.java} | 8 ++- .../springconfig/web/WebMvcConfig.java | 2 +- src/main/resources/logback-spring.xml | 54 +++++++++++++++++++ 4 files changed, 64 insertions(+), 2 deletions(-) rename src/main/java/com/dnd/gooding/springconfig/web/{MdcLoggingInterceptor.java => MDCLoggingInterceptor.java} (72%) create mode 100644 src/main/resources/logback-spring.xml diff --git a/build.gradle b/build.gradle index 20ac04d..6d2f809 100644 --- a/build.gradle +++ b/build.gradle @@ -38,6 +38,8 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-validation' implementation group: 'commons-codec', name: 'commons-codec', version: '1.9' implementation 'com.google.code.gson:gson:2.10.1' + implementation 'com.google.guava:guava:11.0.2' + implementation group: 'net.jodah', name: 'typetools', version: '0.4.2' developmentOnly 'org.springframework.boot:spring-boot-devtools' diff --git a/src/main/java/com/dnd/gooding/springconfig/web/MdcLoggingInterceptor.java b/src/main/java/com/dnd/gooding/springconfig/web/MDCLoggingInterceptor.java similarity index 72% rename from src/main/java/com/dnd/gooding/springconfig/web/MdcLoggingInterceptor.java rename to src/main/java/com/dnd/gooding/springconfig/web/MDCLoggingInterceptor.java index 042e060..8c94d1e 100644 --- a/src/main/java/com/dnd/gooding/springconfig/web/MdcLoggingInterceptor.java +++ b/src/main/java/com/dnd/gooding/springconfig/web/MDCLoggingInterceptor.java @@ -8,9 +8,12 @@ import org.springframework.web.servlet.HandlerInterceptor; @Slf4j -public class MdcLoggingInterceptor implements HandlerInterceptor { +public class MDCLoggingInterceptor implements HandlerInterceptor { public static final String REQUEST_CONTROLLER_MDC_KEY = "handler"; + private static final String REQUEST_URL = "requestUrl"; + private static final String REMOTE_ADDR = "remoteAddr"; + private static final String REQUEST_METHOD = "requestMethod"; @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) @@ -20,6 +23,9 @@ public boolean preHandle(HttpServletRequest request, HttpServletResponse respons String methodName = handlerMethod.getMethod().getName(); String controllerInfo = handlerName + "." + methodName; MDC.put(REQUEST_CONTROLLER_MDC_KEY, controllerInfo); + MDC.put(REMOTE_ADDR, request.getRemoteAddr()); + MDC.put(REQUEST_METHOD, request.getMethod()); + MDC.put(REQUEST_URL, String.valueOf(request.getRequestURL())); } return true; } diff --git a/src/main/java/com/dnd/gooding/springconfig/web/WebMvcConfig.java b/src/main/java/com/dnd/gooding/springconfig/web/WebMvcConfig.java index a225a1b..722b43c 100644 --- a/src/main/java/com/dnd/gooding/springconfig/web/WebMvcConfig.java +++ b/src/main/java/com/dnd/gooding/springconfig/web/WebMvcConfig.java @@ -9,6 +9,6 @@ public class WebMvcConfig implements WebMvcConfigurer { @Override public void addInterceptors(InterceptorRegistry registry) { - registry.addInterceptor(new MdcLoggingInterceptor()); + registry.addInterceptor(new MDCLoggingInterceptor()); } } diff --git a/src/main/resources/logback-spring.xml b/src/main/resources/logback-spring.xml new file mode 100644 index 0000000..3966427 --- /dev/null +++ b/src/main/resources/logback-spring.xml @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + ${LOG_PATTERN} + + + + + + + ${LOG_PATH}/${LOG_FILE_NAME}.log + + + ${LOG_PATTERN} + + + + + ${LOG_PATH}/%d{yyyy-MM, aux}/${LOG_FILE_NAME}.%d{yyyy-MM-dd}.log + + + + 20GB + + + + + + + + + + + \ No newline at end of file