본문 바로가기

study/java

[MyBatis] SpringBoot MyBatis 쿼리 로그 설정하기

의존성(dependency) 추가

implementation "org.bgee.log4jdbc-log4j2:log4jdbc-log4j2-jdbc4:1.16"

 

프로퍼티 파일 추가

파일 : log4jdbc.log4j2.properties

경로 : src/main/resources

log4jdbc.spylogdelegator.name=net.sf.log4jdbc.log.slf4j.Slf4jSpyLogDelegator
log4jdbc.dump.sql.maxlinelength=0

 

datasource 설정

  • 설정 파일 : application.yml
  • driver-class-name 추가
  • jdbc url 변경 : "log4jdbc:" 추가
spring:
	datasource:
		driver-class-name: net.sf.log4jdbc.sql.jdbcapi.DriverSpy
		url: jdbc:log4jdbc:postgresql://localhost:5432/test

 

설정해준 뒤 실행시키면 파라미터가 세팅되지 않은 쿼리와 파라미터 값을 세팅한 쿼리로그가 찍힐 것이다.

 


관련 참고 게시글 : JPA 쿼리 로그 설정

 

[JPA] SpringBoot JPA 쿼리 로그 설정하기

SpringBoot JPA를 사용할 때, SQL 쿼리문을 표출하는 설정 관련해서 정리해보자. 요약 application.yml spring: jpa: properties: hibernate: show_sql: true format_sql: true use_sql_comments: true logging: l.....

haenny.tistory.com

 

 

https://haenny.tistory.com/398 에서 퍼옴 글 정리 잘되어 있음