1. pom.xml 에 log4jdbc 의존성 주입

<!-- https://mvnrepository.com/artifact/org.bgee.log4jdbc-log4j2/log4jdbc-log4j2-jdbc4.1 -->
		<dependency>
		    <groupId>org.bgee.log4jdbc-log4j2</groupId>
		    <artifactId>log4jdbc-log4j2-jdbc4.1</artifactId>
		    <version>1.16</version>
		</dependency>

 

 

2. application.properties 수정

server.port=8080
# 소스 수정시 서버 재시작 설정
spring.devtools.restart.enabled=true

# as-is
#spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
#spring.datasource.url=jdbc:mysql://localhost:3306/book_ex?serverTimezone=UTC
# to-be
spring.datasource.driver-class-name=net.sf.log4jdbc.sql.jdbcapi.DriverSpy
spring.datasource.url=jdbc:log4jdbc:mysql://localhost:3306/book_ex?characterEncoding=UTF-8&serverTimezone=UTC

spring.datasource.username=ansejjang
spring.datasource.password=chlrkd11

mybatis.type-aliases-package=com.anse.web.model
mybatis.config-location=classpath:mybatis-config.xml
mybatis.mapper-locations=classpath:mapper/*.xmlxml

 

3. log4jdbc.log4j2.properties 파일 생성

- src/main/resources 에 생성

log4jdbc.spylogdelegator.name=net.sf.log4jdbc.log.slf4j.Slf4jSpyLogDelegator

 

4. logback.xml 파일 생성

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration>
<configuration>
	<include resource="org/springframework/boot/logging/logback/base.xml" />
	<logger name="jdbc.splonly" 		level="DEBUG" />
	<logger name="jdbc.sqltiming" 		level="DEBUG" />
	<logger name="jdbc.audit" 			level="ERROR" />
	<logger name="jdbc.resultset" 		level="ERROR" />
	<logger name="jdbc.resultsettable" 	level="DEBUG" />
	<logger name="jdbc.connection" 		level="WARN" />
</configuration>

 

5. 테스트

+ Recent posts