Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way in spring for logging queries of specific JPA repository?

I have several JPA repositories in a package and I want to log queries of only one specific repository. I know there are following properties in spring:

  1. logging.level.org.hibernate.SQL=DEBUG
  2. logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE

But these properties log sql statements of all the repositories. I want these properties to work only for given repository. Is there a way in spring to configure for such requirement?

like image 281
Muneeb Shahid Avatar asked Nov 29 '25 19:11

Muneeb Shahid


1 Answers

There is no such feature in Spring. What you could do is writing a wrapper or a proxy, wrapping the repositories in question and before each call setting a value in the MDC and use that for filtering by writing an EvaluatorFilter accessing the MDC of the ILoggingEvent

Something similar should be possible with other Logging frameworks.

like image 147
Jens Schauder Avatar answered Dec 02 '25 08:12

Jens Schauder



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!