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/**,
</package.exclude.base>
</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>
<dependency>
<groupId>org.springframework.boot</groupId>
@ -379,6 +286,7 @@
</configuration>
</plugin>
<!-- queryDsl compile sources -->
<plugin>
<groupId>com.mysema.maven</groupId>
<artifactId>apt-maven-plugin</artifactId>
@ -390,14 +298,31 @@
<goal>process</goal>
</goals>
<configuration>
<outputDirectory>target/generated-sources/java</outputDirectory>
<!-- <processor>com.mysema.query.apt.jpa.JPAAnnotationProcessor</processor> -->
<outputDirectory>${project.build.directory}/generated-sources/java</outputDirectory>
<processor>com.querydsl.apt.jpa.JPAAnnotationProcessor</processor>
</configuration>
</execution>
</executions>
</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>
<groupId>org.apache.maven.plugins</groupId>
@ -448,4 +373,98 @@
</plugins>
</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>

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

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

@ -4,8 +4,8 @@ decorator:
enable-logging: true #p6spy logging 활성화 여부
multiline: true
logging: slf4j
# custom-appender-class: com.p6spy.engine.spy.appender.Slf4JLogger
# log-format: cokr.xit.ens.core.config.support.P6spySqlFormatConfiguration
# custom-appender-class: com.p6spy.engine.spy.appender.Slf4JLogger
# log-format: cokr.xit.ens.core.config.support.P6spySqlFormatConfiguration
tracing:
include-parameter-values: true
@ -16,17 +16,18 @@ logging:
level:
root: info
'[org.hibernate.type.descriptor.sql]': off #jpa "?" 부분(binding 파라미터) 출력
# '[org.springframework.orm.jpa]': debug
# '[org.springframework.transaction]': debug
# '[org.springframework.transaction.interceptor]': trace
# '[org.springframework.jdbc.core]': off
# '[org.springframework.orm]': off
# '[org.springframework.orm.hibernate5]': off
# '[com.p6spy.engine.logging]': off
# '[com.p6spy]': off
# '[org.hibernate]': off
# '[org.hibernate.sql]': off
# '[org.hibernate.jpa]': off
# '[org.springframework.orm.jpa]': debug
# '[org.springframework.transaction]': debug
# '[org.springframework.transaction.interceptor]': trace
# '[org.springframework.jdbc.core]': off
# '[org.springframework.orm]': off
# '[org.springframework.orm.hibernate5]': off
# '[com.p6spy.engine.logging]': off
# '[com.p6spy]': off
# '[org.hibernate]': off
# '[org.hibernate.sql]': off
# '[org.hibernate.jpa]': off
'[org.mariadb.jdbc.internal.logging]': WARN
exception-conversion-word: '%wEx'
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}'
@ -41,4 +42,4 @@ logging:
# '[org.springframework]': debug
# '[org.hibernate]': info
# slack:
# webhook-uri: https://hooks.slack.com/services/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
# webhook-uri: https://hooks.slack.com/services/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

Loading…
Cancel
Save