SQL log 설정 반영

dev
Jonguk. Lim 6 months ago
parent 4403a10b9a
commit f0197fa046

@ -169,13 +169,6 @@
<!-- </dependency>-->
<!-- spy driver -->
<dependency>
<groupId>org.bgee.log4jdbc-log4j2</groupId>
<artifactId>log4jdbc-log4j2-jdbc4</artifactId>
<version>1.16</version>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>

@ -23,9 +23,9 @@ import ch.qos.logback.core.spi.FilterReply;
public class ExcludeLogFilter extends Filter<ILoggingEvent> {
@Override
public FilterReply decide(ILoggingEvent event) {
if (event.getMessage().contains("==> Preparing:")
|| event.getMessage().contains("==> Parameters:")
|| event.getMessage().contains("org.hibernate.SQL")
if (//event.getMessage().contains("==> Preparing:")
//|| event.getMessage().contains("==> Parameters:")
event.getMessage().contains("org.hibernate.SQL")
|| event.getMessage().contains("org.hibernate.type.descriptor.sql")
|| event.getMessage().contains(". PreparedStatement.")
) {

@ -106,6 +106,8 @@ springdoc:
# enable-logging: true
logging:
# sql log format define
config: classpath:logback-spring.xml
pattern:
console: '%d{yyyy-MM-dd HH:mm:ss.SSS} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr([%18.18thread]){magenta}[traceId=%X{request_trace_id}] %clr([%-35.35logger{35}::%-25.25method{25}:%4line]){cyan} %clr(%m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}){faint}'
file: '%d{yyyy-MM-dd HH:mm:ss.SSS} ${LOG_LEVEL_PATTERN:-%5p} [%18.18thread][traceId=%X{request_trace_id}] [%-35.35logger{35}::%-25.25method{25}:%4line] %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}'
@ -113,13 +115,11 @@ logging:
root: info
web: debug
cokr.xit: debug
log4jdbc.log4j2: info
# org.springframework.jdbc.core: debug
# org.springframework.jdbc.connection.init: debug
# log file
file:
path: ${app.data.root.path}/logs
name: ${spring.application.name}
---
spring:
config:
@ -140,17 +140,6 @@ spring:
schema-locations: classpath:database/schema.sql
# data-locations: classpath:database/data.sql
# datasource:
# hikari:
# driver-class-name: org.h2.Driver
# jdbc-url: jdbc:h2:~/test;AUTO_SERVER=true;MODE=MySQL;DATABASE_TO_LOWER=TRUE
# # jdbc-url: jdbc:h2:mem:xitdb;MODE=MySQL;DATABASE_TO_LOWER=TRUE
# #jdbc-url: jdbc:h2:tcp://localhost:9092/mem:testdb;MODE=MySQL;DATABASE_TO_LOWER=TRUE
# username: sa
# password:
# auto-commit: false
# read-only: false
app:
swagger:
url:

@ -0,0 +1,3 @@
log4jdbc.spylogdelegator.name=net.sf.log4jdbc.log.slf4j.Slf4jSpyLogDelegator
log4jdbc.dump.sql.maxlinelength=0
log4jdbc.drivers=org.mariadb.jdbc.Driver

@ -32,6 +32,18 @@
<charset>${CONSOLE_LOG_CHARSET}</charset>
</encoder>
</appender>
<!-- ============================================================================= -->
<!-- SQL logging Appender defined -->
<!-- ============================================================================= -->
<appender name="SQL" class="ch.qos.logback.core.ConsoleAppender">
<!-- 기본 출력 로그 제거 -->
<Filter class="cokr.xit.adds.core.support.logback.ExcludeLogFilter"/>
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss} - SQL:\n%msg%n</pattern>
<charset>${CONSOLE_LOG_CHARSET}</charset>
</encoder>
</appender>
<!-- ============================================================================= -->
<!-- ============================================================================= -->
@ -106,6 +118,15 @@
<logger name="org.mybatis.spring.SqlSessionUtils" level="DEBUG" />
<!-- log4jdbc 옵션 설정 -->
<logger name="jdbc" level="OFF" additivity="false"/>
<!-- SQL문 출력 -->
<logger name="jdbc.sqlonly" level="OFF" additivity="false"/>
<!-- result를 포함한 모든 JDBC 호출 정보 -->
<logger name="jdbc.resultset" level="OFF" additivity="false"/>
<!-- DB connection open/close -->
<logger name="jdbc.connection" level="OFF" additivity="false"/>
<!-- resultset을 제외한 JDBC 호출 정보 -->
<logger name="jdbc.audit" level="OFF" additivity="false"/>
<logger name="org.mariadb.jdbc" level="ERROR" additivity="false"/>
<springProfile name="prod">
<!-- 운영 환경에서만 sql문 및 결과 출력하지 않음 -->
@ -118,20 +139,13 @@
<springProfile name="local, dev">
<!-- 로컬, 개발 환경에서는 sql문 및 결과 출력 -->
<!-- SQL문과 소요된 시간 -->
<logger name="jdbc.sqltiming" level="DEBUG" additivity="false"/>
<logger name="jdbc.sqltiming" level="DEBUG" additivity="false">
<appender-ref ref="SQL"/>
</logger>
<!-- SQL 결과 조회된 데이터를 table 형식으로 출력 -->
<logger name="jdbc.resultsettable" level="DEBUG" additivity="false"/>
<logger name="jdbc.resultsettable" level="OFF" additivity="false"/>
</springProfile>
<!-- SQL문 출력 -->
<logger name="jdbc.sqlonly" level="OFF" additivity="false"/>
<!-- result를 포함한 모든 JDBC 호출 정보 -->
<logger name="jdbc.resultset" level="OFF" additivity="false"/>
<!-- DB connection open/close -->
<logger name="jdbc.connection" level="OFF" additivity="false"/>
<!-- resultset을 제외한 JDBC 호출 정보 -->
<logger name="jdbc.audit" level="OFF" additivity="false"/>
<logger name="org.mariadb.jdbc" level="ERROR" additivity="false"/>
<!-- DB Connection Pool 관련 -->
<logger name="com.zaxxer.hikari.pool.PoolBase" level="ERROR" />

Loading…
Cancel
Save