반응형
0. 개발환경
- Spring Boot 2.6.0
- Gradle
- Java11
- H2 Database
- IntelliJ
1. build.gradle 의존성 추가
runtimeOnly 'com.h2database:h2'
implementation 'org.bgee.log4jdbc-log4j2:log4jdbc-log4j2-jdbc4.1:1.16'
2. src/main/resources/log4jdbc.log4j2.properties 파일 추가
log4jdbc.spylogdelegator.name=net.sf.log4jdbc.log.slf4j.Slf4jSpyLogDelegator
log4jdbc.dump.sql.maxlinelength=0
3. application.properties H2 database 설정 수정
spring.datasource.url=jdbc:log4jdbc:h2:mem:test
spring.datasource.driver-class-name=net.sf.log4jdbc.sql.jdbcapi.DriverSpy
4. src/main/resources/logback.xml 파일 생성
<configuration>
<!-- Appender, 출력 형식 지정 -->
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{yyyy.MM.dd HH:mm:ss.SSS} {%thread} %-5level %logger{5} - %msg %n</pattern>
</encoder>
</appender>
<logger name="jdbc.resultsettable" level="DEBUG" />
<logger name="jdbc.sqltiming" level="DEBUG" />
<logger name="jdbc.resultset" level="OFF" />
<logger name="jdbc.sqlonly" level="OFF" />
<logger name="jdbc.audit" level="OFF" />
<logger name="jdbc.connection" level="OFF" />
<root level="INFO">
<appender-ref ref="console"></appender-ref>
</root>
</configuration>