Search code examples
javaspringhibernatespring-data-jpalogback

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?


Solution

  • 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.