feat: 로깅 추가

- p6spy SQL log
      - request web log
main
Jonguk. Lim 12 months ago
parent 97f003a52b
commit 3bda2bf365

@ -418,9 +418,16 @@
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java --> <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency> <dependency>
<groupId>org.seleniumhq.selenium</groupId> <groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId> <artifactId>selenium-java</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<!-- Springboot 자동설정 -->
<dependency>
<groupId>com.github.gavlyukovskiy</groupId>
<artifactId>p6spy-spring-boot-starter</artifactId>
<version>1.8.1</version>
</dependency>
</dependencies> </dependencies>
<build> <build>

@ -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.*;
/**
* <pre>
* 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
*
* </pre>
* @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);
}
}

@ -1,9 +1,14 @@
package egovframework.com.security; 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.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.core.*;
import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.filter.*;
import org.springframework.web.method.support.HandlerMethodArgumentResolver; import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.view.json.*; import org.springframework.web.servlet.view.json.*;
@ -15,6 +20,9 @@ import lombok.RequiredArgsConstructor;
import java.util.List; import java.util.List;
import javax.servlet.*;
import javax.servlet.http.*;
/** /**
* fileName : WebMvcConfig * fileName : WebMvcConfig
* author : crlee * author : crlee
@ -28,7 +36,13 @@ import java.util.List;
@Configuration @Configuration
@RequiredArgsConstructor @RequiredArgsConstructor
public class WebMvcConfig implements WebMvcConfigurer { public class WebMvcConfig implements WebMvcConfigurer {
/**
* logging exclude path
*/
@Value("${app.log.request.exclude-patterns}")
private List<String> EXCLUDE_URL_REGEXS;
private final ObjectMapper objectMapper; private final ObjectMapper objectMapper;
@Override @Override
@ -47,4 +61,31 @@ public class WebMvcConfig implements WebMvcConfigurer {
public MappingJackson2JsonView mappingJackson2JsonView() { public MappingJackson2JsonView mappingJackson2JsonView() {
return new 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<Filter> bean = new FilterRegistrationBean<>(loggingFilter);
bean.setOrder(Ordered.HIGHEST_PRECEDENCE);
bean.addUrlPatterns("/*");
return bean;
}
} }

@ -43,8 +43,10 @@ Globals:
# DB 접근 정보 # DB 접근 정보
maria: maria:
DriverClassName: net.sf.log4jdbc.DriverSpy # DriverClassName: net.sf.log4jdbc.DriverSpy
Url: jdbc:log4jdbc:mariadb://211.119.124.9:4407/egov # 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 UserName: egov
Password: xit1807 Password: xit1807
oracle: oracle:
@ -138,7 +140,7 @@ logging:
audit: OFF audit: OFF
only: OFF only: OFF
org: org:
springframework: DEBUG springframework: INFO
hibernate: hibernate:
validator: validator:
internal: INFO internal: INFO
@ -149,4 +151,8 @@ logging:
app: app:
auth: auth:
save: save:
type: HEADER type: HEADER
log:
request:
common-enabled: true
exclude-patterns: '/swagger-ui/(.*), /api-docs/(.*), /favicon.ico, /css/(.*), /images/(.*), /js/(.*)'
Loading…
Cancel
Save