config: hibernate SQL log disable

p6spy log 재정의
        pom.xml 설정 정리
main
Jonguk. Lim 4 months ago
parent cda48816f5
commit 5d86c30b83

41
.gitignore vendored

@ -0,0 +1,41 @@
HELP.md
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/
### VS Code ###
.vscode/
### h2db ###
*.mv.db
*exchange*.xml
pack.xml
*.pid
logs/

@ -37,100 +37,7 @@
WEB-INF/classes/**/ens/modules/example/**, WEB-INF/classes/**/ens/modules/example/**,
</package.exclude.base> </package.exclude.base>
</properties> </properties>
<profiles>
<profile>
<id>local</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<spring.profiles.active>local</spring.profiles.active>
<packageIncludesByProfile>
${package.include.base}
WEB-INF/classes/**/ens/batch/**,
WEB-INF/classes/**/ens/modules/**,
<!-- WEB-INF/classes/**/ens/biz/iup/**,-->
WEB-INF/classes/application-local*.yml,
</packageIncludesByProfile>
<packageExcludesByProfile>
</packageExcludesByProfile>
</properties>
</profile>
<profile>
<id>prod-iup</id>
<properties>
<spring.profiles.active>prod-iup</spring.profiles.active>
<packageIncludesByProfile>
${package.include.base}
WEB-INF/classes/**/ens/modules/**,
<!-- WEB-INF/classes/**/ens/modules/common/**,-->
<!-- WEB-INF/classes/**/ens/modules/kkomydoc/**,-->
<!-- WEB-INF/classes/**/ens/modules/nvsigntalk/**,-->
WEB-INF/classes/**/ens/biz/iup/**,
WEB-INF/classes/application-prod-iup.yml,
WEB-INF/classes/mybatis-mapper/**,
</packageIncludesByProfile>
<packageExcludesByProfile>
${package.exclude.base}
WEB-INF/classes/**/ens/batch/**/EnsScheduler.class,
WEB-INF/classes/**/ens/biz/iup/_legacy/**,
WEB-INF/classes/**/ens/biz/iup/alimtalk/**,
</packageExcludesByProfile>
</properties>
</profile>
<profile>
<id>prod-traffic-cc</id>
<properties>
<spring.profiles.active>prod-traffic</spring.profiles.active>
<packageIncludesByProfile>
${package.include.base}
WEB-INF/classes/**/ens/batch/**/EnsKkoMydocScheduler.class,
WEB-INF/classes/**/ens/modules/common/**,
WEB-INF/classes/**/ens/modules/kkomydoc/**,
WEB-INF/classes/**/ens/biz/traffic/chuncheon/**,
WEB-INF/classes/application-prod-traffic.yml,
</packageIncludesByProfile>
<packageExcludesByProfile>
${package.exclude.base}
WEB-INF/classes/**/ens/modules/common/ctgy/intgrnnoti/**,
</packageExcludesByProfile>
</properties>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<excludes>
<exclude>mybatis-mapper/**</exclude>
</excludes>
</resource>
</resources>
</build>
</profile>
<profile>
<id>prod-traffic-cheonan</id>
<properties>
<spring.profiles.active>prod-traffic-cheonan</spring.profiles.active>
<packageIncludesByProfile>
${package.include.base}
WEB-INF/classes/**/ens/batch/**/EnsIntgrnScheduler.class,
WEB-INF/classes/**/ens/batch/**/EnsKkoMydocScheduler.class,
WEB-INF/classes/**/ens/batch/**/EnsKtGibisScheduler.class,
WEB-INF/classes/**/ens/modules/**,
<!-- WEB-INF/classes/**/ens/modules/common/**,-->
<!-- WEB-INF/classes/**/ens/modules/kkomydoc/**,-->
<!-- WEB-INF/classes/**/ens/modules/ktsigntalk/gibis/**,-->
<!-- WEB-INF/classes/**/ens/modules/ktsigntalk/common/**,-->
WEB-INF/classes/**/ens/biz/traffic/cheonan/**,
WEB-INF/classes/application-prod-traffic-cheonan.yml,
WEB-INF/classes/mybatis-mapper/**,
</packageIncludesByProfile>
<packageExcludesByProfile>
${package.exclude.base}
</packageExcludesByProfile>
<webapp.lib.jdbc.oracle>ojdbc6</webapp.lib.jdbc.oracle>
</properties>
</profile>
</profiles>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
@ -379,6 +286,7 @@
</configuration> </configuration>
</plugin> </plugin>
<!-- queryDsl compile sources -->
<plugin> <plugin>
<groupId>com.mysema.maven</groupId> <groupId>com.mysema.maven</groupId>
<artifactId>apt-maven-plugin</artifactId> <artifactId>apt-maven-plugin</artifactId>
@ -390,14 +298,31 @@
<goal>process</goal> <goal>process</goal>
</goals> </goals>
<configuration> <configuration>
<outputDirectory>target/generated-sources/java</outputDirectory> <outputDirectory>${project.build.directory}/generated-sources/java</outputDirectory>
<!-- <processor>com.mysema.query.apt.jpa.JPAAnnotationProcessor</processor> -->
<processor>com.querydsl.apt.jpa.JPAAnnotationProcessor</processor> <processor>com.querydsl.apt.jpa.JPAAnnotationProcessor</processor>
</configuration> </configuration>
</execution> </execution>
</executions> </executions>
</plugin> </plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/generated-sources/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<!-- queryDsl compile sources -->
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
@ -448,4 +373,98 @@
</plugins> </plugins>
</build> </build>
<profiles>
<profile>
<id>local</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<spring.profiles.active>local</spring.profiles.active>
<packageIncludesByProfile>
${package.include.base}
WEB-INF/classes/**/ens/batch/**,
WEB-INF/classes/**/ens/modules/**,
<!-- WEB-INF/classes/**/ens/biz/iup/**,-->
WEB-INF/classes/application-local*.yml,
</packageIncludesByProfile>
<packageExcludesByProfile>
</packageExcludesByProfile>
</properties>
</profile>
<profile>
<id>prod-iup</id>
<properties>
<spring.profiles.active>prod-iup</spring.profiles.active>
<packageIncludesByProfile>
${package.include.base}
WEB-INF/classes/**/ens/modules/**,
<!-- WEB-INF/classes/**/ens/modules/common/**,-->
<!-- WEB-INF/classes/**/ens/modules/kkomydoc/**,-->
<!-- WEB-INF/classes/**/ens/modules/nvsigntalk/**,-->
WEB-INF/classes/**/ens/biz/iup/**,
WEB-INF/classes/application-prod-iup.yml,
WEB-INF/classes/mybatis-mapper/**,
</packageIncludesByProfile>
<packageExcludesByProfile>
${package.exclude.base}
WEB-INF/classes/**/ens/batch/**/EnsScheduler.class,
WEB-INF/classes/**/ens/biz/iup/_legacy/**,
WEB-INF/classes/**/ens/biz/iup/alimtalk/**,
</packageExcludesByProfile>
</properties>
</profile>
<profile>
<id>prod-traffic-cc</id>
<properties>
<spring.profiles.active>prod-traffic</spring.profiles.active>
<packageIncludesByProfile>
${package.include.base}
WEB-INF/classes/**/ens/batch/**/EnsKkoMydocScheduler.class,
WEB-INF/classes/**/ens/modules/common/**,
WEB-INF/classes/**/ens/modules/kkomydoc/**,
WEB-INF/classes/**/ens/biz/traffic/chuncheon/**,
WEB-INF/classes/application-prod-traffic.yml,
</packageIncludesByProfile>
<packageExcludesByProfile>
${package.exclude.base}
WEB-INF/classes/**/ens/modules/common/ctgy/intgrnnoti/**,
</packageExcludesByProfile>
</properties>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<excludes>
<exclude>mybatis-mapper/**</exclude>
</excludes>
</resource>
</resources>
</build>
</profile>
<profile>
<id>prod-traffic-cheonan</id>
<properties>
<spring.profiles.active>prod-traffic-cheonan</spring.profiles.active>
<packageIncludesByProfile>
${package.include.base}
WEB-INF/classes/**/ens/batch/**/EnsIntgrnScheduler.class,
WEB-INF/classes/**/ens/batch/**/EnsKkoMydocScheduler.class,
WEB-INF/classes/**/ens/batch/**/EnsKtGibisScheduler.class,
WEB-INF/classes/**/ens/modules/**,
<!-- WEB-INF/classes/**/ens/modules/common/**,-->
<!-- WEB-INF/classes/**/ens/modules/kkomydoc/**,-->
<!-- WEB-INF/classes/**/ens/modules/ktsigntalk/gibis/**,-->
<!-- WEB-INF/classes/**/ens/modules/ktsigntalk/common/**,-->
WEB-INF/classes/**/ens/biz/traffic/cheonan/**,
WEB-INF/classes/application-prod-traffic-cheonan.yml,
WEB-INF/classes/mybatis-mapper/**,
</packageIncludesByProfile>
<packageExcludesByProfile>
${package.exclude.base}
</packageExcludesByProfile>
<webapp.lib.jdbc.oracle>ojdbc6</webapp.lib.jdbc.oracle>
</properties>
</profile>
</profiles>
</project> </project>

@ -1,72 +1,72 @@
package cokr.xit.ens.core.config.logging; package cokr.xit.ens.core.config.logging;
import java.util.Locale;
import org.hibernate.engine.jdbc.internal.FormatStyle;
import com.p6spy.engine.logging.Category; import com.p6spy.engine.logging.Category;
import com.p6spy.engine.spy.appender.MessageFormattingStrategy; import com.p6spy.engine.spy.appender.MessageFormattingStrategy;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.engine.jdbc.internal.FormatStyle;
import java.util.Locale; import lombok.extern.slf4j.Slf4j;
import java.util.Objects;
import java.util.Stack;
@Slf4j @Slf4j
public class P6spySqlFormatConfiguration implements MessageFormattingStrategy { public class P6spySqlFormatConfiguration implements MessageFormattingStrategy {
@Override private static final String NEW_LINE = "\n";
public String formatMessage(final int connectionId, final String now, final long elapsed, final String category, final String prepared, final String sql, final String url) { private static final String TAP = "\t";
Stack<String> callStack = new Stack<>(); private static final String CREATE = "create";
StackTraceElement[] stackTrace = new Throwable().getStackTrace(); private static final String ALTER = "alter";
private static final String DROP = "drop";
for (StackTraceElement stackTraceElement : stackTrace) { private static final String COMMENT = "comment";
String trace = stackTraceElement.toString();
if (trace.startsWith("io.p6spy") && !trace.contains("P6spyPrettySqlFormatter")) {
callStack.push(trace);
}
}
StringBuilder callStackBuilder = new StringBuilder(); @Override
int order = 1; public String formatMessage(int connectionId, String now, long elapsed, String category, String prepared, String sql, String url) {
while(callStack.size() != 0) { if (sql.trim().isEmpty()) {
callStackBuilder.append("\n\t\t").append(order++).append(". ").append(callStack.pop()); return formatByCommand(category);
} } return formatBySql(sql, category) + getAdditionalMessages(elapsed);
String message = new StringBuilder().append("\n\n\tConnection ID: ").append(connectionId)
.append("\n\tExecution Time: ").append(elapsed).append(" ms\n")
.append("\n\tCall Stack (number 1 is entry point): ").append(callStackBuilder).append("\n")
.toString();
return sqlFormat(sql, category, message);
} }
private static String formatByCommand(String category) {
private String sqlFormat(String sql, String category, String message) { return NEW_LINE
if(sql.trim().isEmpty()) { + "Execute Command : "
return ""; + NEW_LINE
+ NEW_LINE
+ TAP
+ category
+ NEW_LINE
+ NEW_LINE
+ "----------------------------------------------------------------------------------------------------";
} }
private String formatBySql(String sql, String category) {
String sqlComment = null; if (isStatementDDL(sql, category)) {
if(Objects.equals(Category.STATEMENT.getName(), category)) { return NEW_LINE
sql = sql.trim().toLowerCase(Locale.ROOT); + "Execute DDL : "
if(sql.startsWith("/*") && sql.contains("*/")){ + NEW_LINE
sqlComment = sql.substring(0, sql.indexOf("*/")+2); + FormatStyle.DDL
sql = sql.substring(sqlComment.length()).trim();
}
if(sql.startsWith("create") || sql.startsWith("alter") || sql.startsWith("comment") || sql.startsWith("drop")) {
sql = FormatStyle.DDL
.getFormatter() .getFormatter()
.format(sql); .format(sql);
} } return NEW_LINE
else { + "Execute DML : "
sql = FormatStyle.BASIC + NEW_LINE
+ FormatStyle.BASIC
.getFormatter() .getFormatter()
.format(sql); .format(sql);
} }
private String getAdditionalMessages(long elapsed) {
return NEW_LINE
+ NEW_LINE
+ String.format("Execution Time: %s ms", elapsed)
+ NEW_LINE
+ "----------------------------------------------------------------------------------------------------";
} }
private boolean isStatementDDL(String sql, String category) {
return new StringBuilder().append("\n") return isStatement(category) && isDDL(sql.trim().toLowerCase(Locale.ROOT));
.append("----------------------------------------------------------------------------------------------------") }
.append(sqlComment == null ? "" : "\n" + sqlComment) private boolean isStatement(String category) {
.append(sql) return Category.STATEMENT.getName().equals(category);
.append(message) }
.append("----------------------------------------------------------------------------------------------------") private boolean isDDL(String lowerSql) {
.toString(); return lowerSql.startsWith(CREATE)
|| lowerSql.startsWith(ALTER)
|| lowerSql.startsWith(DROP)
|| lowerSql.startsWith(COMMENT);
} }
} }

@ -1,5 +1,5 @@
server: server:
shutdown: graceful
servlet: servlet:
context-path: context-path:
error: error:
@ -14,19 +14,19 @@ server:
spring: spring:
profiles: profiles:
# active: local # active: local
active: '@spring.profiles.active@' active: '@spring.profiles.active@'
# include: # include:
# prodDB # prodDB
# group: # group:
# local: # local:
# - localDB # - localDB
# prod: # prod:
# - prodDB # - prodDB
config: config:
import: classpath:config/conf-app.yml, classpath:config/conf-contract.yml, classpath:config/conf-log.yml, classpath:config/conf-mybatis.yml, classpath:config/conf-policy.yml, classpath:config/conf-slack.yml import: classpath:config/conf-app.yml, classpath:config/conf-contract.yml, classpath:config/conf-log.yml, classpath:config/conf-mybatis.yml, classpath:config/conf-policy.yml, classpath:config/conf-slack.yml
# main: # main:
# allow-bean-definition-overriding: true # allow-bean-definition-overriding: true
pid: pid:
file: mdpost.pid file: mdpost.pid
@ -49,7 +49,7 @@ spring:
connection-test-query: SELECT 1 connection-test-query: SELECT 1
minimum-idle: 10 minimum-idle: 10
maximum-pool-size: 50 maximum-pool-size: 50
# transaction-isolation: TRANSACTION_READ_UNCOMMITTED # transaction-isolation: TRANSACTION_READ_UNCOMMITTED
transaction-isolation: TRANSACTION_READ_COMMITTED transaction-isolation: TRANSACTION_READ_COMMITTED
pool-name: pool-xitworld pool-name: pool-xitworld
data-source-properties: data-source-properties:
@ -58,23 +58,23 @@ spring:
jpa: jpa:
database-platform: org.hibernate.dialect.MariaDB103Dialect database-platform: org.hibernate.dialect.MariaDB103Dialect
show-sql: true # show-sql: true
# generate-ddl: true #TODO: 필요 시 주석해제. generate-ddl를 true 설정 시 ddl-auto의 설정값과 무관하게 DDL 스크립트 실행 # generate-ddl: true #TODO: 필요 시 주석해제. generate-ddl를 true 설정 시 ddl-auto의 설정값과 무관하게 DDL 스크립트 실행
hibernate: hibernate:
ddl-auto: none ddl-auto: none
naming: naming:
# implicit-strategy: org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy # implicit-strategy: org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy
physical-strategy: org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy physical-strategy: org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy
properties: properties:
hibernate: hibernate:
format_sql: true # format_sql: true
use_sql_comments: true # use_sql_comments: true
order_inserts: true order_inserts: true
order_updates: true order_updates: true
jdbc: jdbc:
batch_size: 200 batch_size: 200
# default_batch_fetch_size: ${chunkSize:100} # default_batch_fetch_size: ${chunkSize:100}
# dialect: org.hibernate.dialect.MySQL57InnoDBDialect # dialect: org.hibernate.dialect.MySQL57InnoDBDialect
cache: cache:
@ -82,11 +82,11 @@ spring:
redis: redis:
host: ${server.host:localhost} host: ${server.host:localhost}
port: 16379 port: 16379
# password: # password:
# database: # database:
# timeout: # timeout:
# sentinel: # sentinel:
# master: # master:
data: data:
redis: redis:
repositories: repositories:

@ -4,8 +4,8 @@ decorator:
enable-logging: true #p6spy logging 활성화 여부 enable-logging: true #p6spy logging 활성화 여부
multiline: true multiline: true
logging: slf4j logging: slf4j
# custom-appender-class: com.p6spy.engine.spy.appender.Slf4JLogger # custom-appender-class: com.p6spy.engine.spy.appender.Slf4JLogger
# log-format: cokr.xit.ens.core.config.support.P6spySqlFormatConfiguration # log-format: cokr.xit.ens.core.config.support.P6spySqlFormatConfiguration
tracing: tracing:
include-parameter-values: true include-parameter-values: true
@ -16,17 +16,18 @@ logging:
level: level:
root: info root: info
'[org.hibernate.type.descriptor.sql]': off #jpa "?" 부분(binding 파라미터) 출력 '[org.hibernate.type.descriptor.sql]': off #jpa "?" 부분(binding 파라미터) 출력
# '[org.springframework.orm.jpa]': debug # '[org.springframework.orm.jpa]': debug
# '[org.springframework.transaction]': debug # '[org.springframework.transaction]': debug
# '[org.springframework.transaction.interceptor]': trace # '[org.springframework.transaction.interceptor]': trace
# '[org.springframework.jdbc.core]': off # '[org.springframework.jdbc.core]': off
# '[org.springframework.orm]': off # '[org.springframework.orm]': off
# '[org.springframework.orm.hibernate5]': off # '[org.springframework.orm.hibernate5]': off
# '[com.p6spy.engine.logging]': off # '[com.p6spy.engine.logging]': off
# '[com.p6spy]': off # '[com.p6spy]': off
# '[org.hibernate]': off # '[org.hibernate]': off
# '[org.hibernate.sql]': off # '[org.hibernate.sql]': off
# '[org.hibernate.jpa]': off # '[org.hibernate.jpa]': off
'[org.mariadb.jdbc.internal.logging]': WARN
exception-conversion-word: '%wEx' exception-conversion-word: '%wEx'
pattern: pattern:
console: '%d{yyyy-MM-dd HH:mm:ss.SSS} %clr(${LOG_LEVEL_PATTERN:-%5p}){green} %clr([%18thread]){magenta} %clr(%-40.40logger{39}%line){cyan} %clr(: %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}){faint}' console: '%d{yyyy-MM-dd HH:mm:ss.SSS} %clr(${LOG_LEVEL_PATTERN:-%5p}){green} %clr([%18thread]){magenta} %clr(%-40.40logger{39}%line){cyan} %clr(: %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}){faint}'

Loading…
Cancel
Save