diff --git a/pom.xml b/pom.xml index 8400a04..4b91132 100644 --- a/pom.xml +++ b/pom.xml @@ -418,9 +418,16 @@ org.seleniumhq.selenium - selenium-java - test - + selenium-java + test + + + + + com.github.gavlyukovskiy + p6spy-spring-boot-starter + 1.8.1 + diff --git a/src/main/java/com/xit/core/config/support/P6SpySqlMultilineFormat.java b/src/main/java/com/xit/core/config/support/P6SpySqlMultilineFormat.java new file mode 100644 index 0000000..bbf38ee --- /dev/null +++ b/src/main/java/com/xit/core/config/support/P6SpySqlMultilineFormat.java @@ -0,0 +1,40 @@ +package com.xit.core.config.support; + +import javax.annotation.*; + +import org.springframework.context.annotation.*; + +import com.p6spy.engine.spy.*; +import com.p6spy.engine.spy.appender.*; + +/** + *
+ * description : P6Spy SQL 로그 Multiline 출력 포맷 Custom
+ *               - sql이 있는 경우만 출력
+ *               - prepared, url(DB), now 출력 제거
+ * packageName : kr.xit.core.spring.config.support
+ * fileName    : P6SpySqlMultilineFormat
+ * author      : julim
+ * date        : 2023-04-28
+ * ======================================================================
+ * 변경일         변경자        변경 내용
+ * ----------------------------------------------------------------------
+ * 2023-04-28    julim       최초 생성
+ *
+ * 
+ * @see com.p6spy.engine.spy.appender.MultiLineFormat + */ + +@Configuration +public class P6SpySqlMultilineFormat implements MessageFormattingStrategy { + + @PostConstruct + public void setLogMessageFormat() { + P6SpyOptions.getActiveInstance().setLogMessageFormat(this.getClass().getName()); + } + + @Override + public String formatMessage(final int connectionId, final String now, final long elapsed, final String category, final String prepared, final String sql, final String url) { + return String.format("connection %d - [%s] | %d ms \n%s", connectionId, category, elapsed, sql); + } +} diff --git a/src/main/java/egovframework/com/security/WebMvcConfig.java b/src/main/java/egovframework/com/security/WebMvcConfig.java index e16b29c..4f36493 100644 --- a/src/main/java/egovframework/com/security/WebMvcConfig.java +++ b/src/main/java/egovframework/com/security/WebMvcConfig.java @@ -1,9 +1,14 @@ package egovframework.com.security; +import org.springframework.beans.factory.annotation.*; +import org.springframework.boot.autoconfigure.condition.*; +import org.springframework.boot.web.servlet.*; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.core.*; import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; +import org.springframework.web.filter.*; import org.springframework.web.method.support.HandlerMethodArgumentResolver; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import org.springframework.web.servlet.view.json.*; @@ -15,6 +20,9 @@ import lombok.RequiredArgsConstructor; import java.util.List; +import javax.servlet.*; +import javax.servlet.http.*; + /** * fileName : WebMvcConfig * author : crlee @@ -28,7 +36,13 @@ import java.util.List; @Configuration @RequiredArgsConstructor public class WebMvcConfig implements WebMvcConfigurer { - + + /** + * logging exclude path + */ + @Value("${app.log.request.exclude-patterns}") + private List EXCLUDE_URL_REGEXS; + private final ObjectMapper objectMapper; @Override @@ -47,4 +61,31 @@ public class WebMvcConfig implements WebMvcConfigurer { public MappingJackson2JsonView mappingJackson2JsonView() { return new MappingJackson2JsonView(); } + + @ConditionalOnProperty(value = "app.log.request.common-enabled", havingValue = "true", matchIfMissing = false) + @Bean + public FilterRegistrationBean requestLoggingFilter() { + CommonsRequestLoggingFilter loggingFilter = new CommonsRequestLoggingFilter(){ + @Override + protected boolean shouldNotFilter(HttpServletRequest request) throws ServletException { + String path = request.getServletPath(); + return EXCLUDE_URL_REGEXS.stream().anyMatch(regex -> path.matches(regex)); + } + }; + loggingFilter.setIncludeClientInfo(true); + loggingFilter.setIncludeHeaders(false); + loggingFilter.setBeforeMessagePrefix("\n//========================== Request(Before) ================================\n"); + loggingFilter.setBeforeMessageSuffix("\n//==========================================================================="); + + loggingFilter.setIncludeQueryString(true); + loggingFilter.setIncludePayload(true); + loggingFilter.setMaxPayloadLength(1024* 1024); + loggingFilter.setAfterMessagePrefix("\n//=========================== Request(After) ================================\n"); + loggingFilter.setAfterMessageSuffix("\n//==========================================================================="); + + FilterRegistrationBean bean = new FilterRegistrationBean<>(loggingFilter); + bean.setOrder(Ordered.HIGHEST_PRECEDENCE); + bean.addUrlPatterns("/*"); + return bean; + } } \ No newline at end of file diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index f121a98..4817ed5 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -43,8 +43,10 @@ Globals: # DB 접근 정보 maria: - DriverClassName: net.sf.log4jdbc.DriverSpy - Url: jdbc:log4jdbc:mariadb://211.119.124.9:4407/egov +# DriverClassName: net.sf.log4jdbc.DriverSpy +# Url: jdbc:log4jdbc:mariadb://211.119.124.9:4407/egov + DriverClassName: org.mariadb.jdbc.Driver + Url: jdbc:mariadb://211.119.124.9:4407/egov UserName: egov Password: xit1807 oracle: @@ -138,7 +140,7 @@ logging: audit: OFF only: OFF org: - springframework: DEBUG + springframework: INFO hibernate: validator: internal: INFO @@ -149,4 +151,8 @@ logging: app: auth: save: - type: HEADER \ No newline at end of file + type: HEADER + log: + request: + common-enabled: true + exclude-patterns: '/swagger-ui/(.*), /api-docs/(.*), /favicon.ico, /css/(.*), /images/(.*), /js/(.*)' \ No newline at end of file