스프링 부트

스프링 부트 JPA 쿼리 파라미터 로그 남기기 (P6Spy 이용)

포스틸 2025. 2. 12. 18:04
반응형

스프링 부트 데이터소스 데코레이터

https://github.com/gavlyukovskiy/spring-boot-data-source-decorator?tab=readme-ov-file#spring-boot-datasource-decorator

 

GitHub - gavlyukovskiy/spring-boot-data-source-decorator: Spring Boot integration with p6spy, datasource-proxy, flexy-pool and s

Spring Boot integration with p6spy, datasource-proxy, flexy-pool and spring-cloud-sleuth - gavlyukovskiy/spring-boot-data-source-decorator

github.com

 

 

위 페이지에서 

  • P6Spy - adds ability to intercept and log sql queries, including interception of a most Connection, Statement and ResultSet methods invocations

를 이용해보겠다.

위 링크를 따라 웹페이지에 가면, 아래 캡쳐 이미지 처럼 현재 최신 버전이 1.10.0 이다.

또, 아래와 같이 넣으라고 한다.

implementation("com.github.gavlyukovskiy:p6spy-spring-boot-starter:${version}")

 

 

이제, 정보를 확인했으니 내 프로젝트의 build.gradle 파일 내용에 추가하자.

implementation 'com.github.gavlyukovskiy:p6spy-spring-boot-starter:1.10.0'

 

이제 테스트를 실행해보자.

2025-02-12T17:58:22.640+09:00 DEBUG 38120 --- [    Test worker] org.hibernate.SQL                        : 
    insert 
    into
        member
        (username, id) 
    values
        (?, ?)
2025-02-12T17:58:22.641+09:00 TRACE 38120 --- [    Test worker] org.hibernate.orm.jdbc.bind              : binding parameter (1:VARCHAR) <- [memberA]
2025-02-12T17:58:22.641+09:00 TRACE 38120 --- [    Test worker] org.hibernate.orm.jdbc.bind              : binding parameter (2:BIGINT) <- [1]
2025-02-12T17:58:22.642+09:00  INFO 38120 --- [    Test worker] p6spy                                    : #1739350702642 | took 0ms | statement | connection 4| url jdbc:h2:tcp://localhost/~/jpashop
insert into member (username,id) values (?,?)
insert into member (username,id) values ('memberA',1);
2025-02-12T17:58:22.644+09:00  INFO 38120 --- [    Test worker] p6spy                                    : #1739350702644 | took 0ms | commit | connection 4| url jdbc:h2:tcp://localhost/~/jpashop

;

 

보기 편하게 잘 출력된다.

반응형