<aside> 🤔 쿼리 로그는 Hibernate 출력으로 하면 되지, 왜 Log4jdbc ?

</aside>

JPA에서 제공하는 spring.jpa.properties.hibernate.generate_statistics=true 옵션을 Properties 파일에 추가하면 간단하게 아래처럼 볼 수 있긴 하다.

Hibernate: 
    select
        products0_.id as id1_3_,
        products0_.big_category as big_cate2_3_,
        products0_.small_category as small_ca3_3_,
        products0_.discount as discount4_3_,
        products0_.evnet_id as evnet_id9_3_,
        products0_.on_sale as on_sale5_3_,
        products0_.price as price6_3_,
        products0_.product_name as product_7_3_,
        products0_.stock as stock8_3_ 
    from
        product products0_ 
    where
        (
            products0_.product_name like ? escape '!'
        ) 
        and products0_.big_category=?
2023-03-14 17:51:26.802  INFO 55776 --- [           main] i.StatisticalLoggingSessionEventListener : Session Metrics {
    9836500 nanoseconds spent acquiring 1 JDBC connections;
    0 nanoseconds spent releasing 0 JDBC connections;
    9961900 nanoseconds spent preparing 1 JDBC statements;
    595164800 nanoseconds spent executing 1 JDBC statements;
    0 nanoseconds spent executing 0 JDBC batches;
    0 nanoseconds spent performing 0 L2C puts;
    0 nanoseconds spent performing 0 L2C hits;
    0 nanoseconds spent performing 0 L2C misses;
    0 nanoseconds spent executing 0 flushes (flushing a total of 0 entities and 0 collections);
    0 nanoseconds spent executing 0 partial-flushes (flushing a total of 0 entities and 0 collections)
}

하지만 로그를 파일로 찍어보는 작업과 쿼리 로그에 대해 더 여러가지 설정으로 볼 수 있게 하고 싶어서 log4jdbc를 적용해 보기로 했다.

<aside> 😉 Log4jdbc 적용 방법

</aside>

<aside> 🎉 Log4jdbc로 로그를 찍은 결과

</aside>

{executed in 9 msec} 처럼 해당 쿼리를 실행하는 시간이 나온다.

설정 따라 추가 정보로 어느 스레드가 전송한 쿼리인지도 볼 수 있고, 해당 쿼리에 대한 결과 값도 볼 수 있어 동시성 테스트에도 잘 사용해 볼 수 있을 듯 하다.