개발용 메모장...

[Java]/[Spring]

[SpringBoot] Database Logging 설정

redeyesboy 2024. 8. 27. 11:43

1. 의존성 추가

- pom.xml

<dependency>
	<groupId>org.bgee.log4jdbc-log4j2</groupId>
	<artifactId>log4jdbc-log4j2-jdbc4.1</artifactId>
	<version>1.16</version>
</dependency>

 

2. 설정 파일 추가

- log4jdbc.log4j2.properties ( /resources/log4jdbc.log4j2.properties )

log4jdbc.spylogdelegator.name=net.sf.log4jdbc.log.slf4j.Slf4jSpyLogDelegator
log4jdbc.dump.sql.maxlinelength=0
log4jdbc.auto.load.popular.drivers=false

 

 

3. datasource 설정 변경

- application.properties

# 수정전

spring.datasource.hikari.driver-class-name=org.mariadb.jdbc.Driver
spring.datasource.hikari.jdbc-url=jdbc:mariadb://localhost:3306/mall

 

# 수정후

spring.datasource.hikari.driver-class-name=net.sf.log4jdbc.sql.jdbcapi.DriverSpy
spring.datasource.hikari.jdbc-url=jdbc:log4jdbc:mariadb://localhost:3306/mall

 

4. Logging 설정 추가

- application.properties

logging.group.jdbc-viewer=jdbc.sqltiming,jdbc.resultsettable
logging.group.jdbc-off=jdbc,jdbc.connection,jdbc.sqlonly,jdbc.audit,jdbc.resultset,jdbc.connection

logging.level.jdbc-viewer=info
logging.level.jdbc-off=off