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);
}
}
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";
StringBuilder callStackBuilder = new StringBuilder();
int order = 1;
while(callStack.size() != 0) {
callStackBuilder.append("\n\t\t").append(order++).append(". ").append(callStack.pop());
}
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 String sqlFormat(String sql, String category, String message) {
@Override
public String formatMessage(int connectionId, String now, long elapsed, String category, String prepared, String sql, String url) {
if (sql.trim().isEmpty()) {
return "";
return formatByCommand(category);
} return formatBySql(sql, category) + getAdditionalMessages(elapsed);
}
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();
private static String formatByCommand(String category) {
return NEW_LINE
+ "Execute Command : "
+ NEW_LINE
+ NEW_LINE
+ TAP
+ category
+ NEW_LINE
+ NEW_LINE
+ "----------------------------------------------------------------------------------------------------";
}
if(sql.startsWith("create") || sql.startsWith("alter") || sql.startsWith("comment") || sql.startsWith("drop")) {
sql = FormatStyle.DDL
private String formatBySql(String sql, String category) {
if (isStatementDDL(sql, category)) {
return NEW_LINE
+ "Execute DDL : "
+ NEW_LINE
+ FormatStyle.DDL
.getFormatter()
.format(sql);
}
else {
sql = FormatStyle.BASIC
} 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
+ "----------------------------------------------------------------------------------------------------";
}
return new StringBuilder().append("\n")
.append("----------------------------------------------------------------------------------------------------")
.append(sqlComment == null ? "" : "\n" + sqlComment)
.append(sql)
.append(message)
.append("----------------------------------------------------------------------------------------------------")
.toString();
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:
@ -58,7 +58,7 @@ spring:
jpa:
database-platform: org.hibernate.dialect.MariaDB103Dialect
show-sql: true
# show-sql: true
# generate-ddl: true #TODO: 필요 시 주석해제. generate-ddl를 true 설정 시 ddl-auto의 설정값과 무관하게 DDL 스크립트 실행
hibernate:
ddl-auto: none
@ -67,8 +67,8 @@ spring:
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:

@ -27,6 +27,7 @@ logging:
# '[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}'

Loading…
Cancel
Save