본문 바로가기

카테고리 없음

[Springboot] hibernate SQL 로깅 설정

 

application.properties 설정, logback-spring.xml 을 사용하여 설정할 수 있음(둘 중 하나만 적용하면됨 )

logback-spring.xml을 이용하면 더 상세한 설정이 가능하다고함

 

1. application.properties 설정으로 로깅 설정

# application.properties

logging.level.org.hibernate.SQL=debug
logging.level.org.hibernate.type=trace




# 로그 편하게 보기 위한 설정
# sql 포맷으로 보기
spring.jpa.properties.hibernate.format_sql=true

# 색상 설정 추가
spring.jpa.properties.hibernate.highlight_sql=true

 

 

2. logback-spring.xml 설정으로 로깅 설정

 # logback-spring.xml
 
 <!-- Hibernate SQL 쿼리 로깅 설정 -->
    <logger name="org.hibernate.SQL" level="DEBUG" additivity="false">
        <appender-ref ref="CONSOLE"/>
        <appender-ref ref="FILE"/>
    </logger>

 

 

3. 위 두 설정을 모두 해제고 아래와 같이 설정하면 [Hibernate] 로그만 확인됨

# application.properties

spring.jpa.show-sql=true