SpringBoot JPA 쿼리 로그 설정하기

이동명·2023년 5월 26일
0
post-thumbnail

application.yml

spring:
  jpa:
    properties:
      hibernate:
        show_sql: true
        format_sql: true
        use_sql_comments: true
logging:
  level:
    org:
      hibernate:
        type:
          descriptor:
            sql: trace

application.properties

spring.jpa.properties.hibernate.show_sql=true
spring.jpa.properties.hibernate.format_sql=true
spring.jpa.properties.hibernate.use_sql_comments=true
logging.level.org.hibernate.type.descriptor.sql=trace

상세

SQL 로그 설정

Hibernate이 DB에 날리는 모든 쿼리(DDL, DML) 표출

application.yml

spring:
    jpa:
      properties:
         hibernate:
            show_sql: true

application.properties

spring.jpa.properties.hibernate.show_sql=true

SQL 포맷 설정!

쿼리 들여쓰기 등의 포맷에 맞춰 표출

application.yml

spring:
    jpa:
      properties:
         hibernate:
            format_sql: true

application.properties

spring.jpa.properties.hibernate.format_sql=true

주석 표시하기

application.yml

spring:
    jpa:
      properties:
         hibernate:
            use_sql_comments: true

application.properties

spring.jpa.properties.hibernate.use_Sql_comments=true

파라미터 값 표출

이 옵션을 사용하지 않으면 기본적으로 파라미터 값이 무엇인지는 알 수 없고, 바인딩 쿼리로그만 찍힌다.

application.yml

logging:
    level:
      org:
         hibernate:
            type:
               descriptor:
                  sql: trace

application.properties

logging.level.org.hibernate.type.descriptor.sql=trace
profile
Web Developer

0개의 댓글