We use this Log4J config to display JTA info:
<category name="org.springframework.transaction">
<priority value="DEBUG"/>
</category>
The resulting log entries are of the type:
15:36:08,048 DEBUG [JtaTransactionManager] [ ] Creating new transaction with name [class]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT
15:36:09,564 DEBUG [JtaTransactionManager] [ ] Initiating transaction commit
… Now we use Spring’s MessageListener to listen to an MQ queue. Problem is this is transactional, and we get the aforementioned logging printed out every 2 seconds.
What we want, is just to have these JTA log statements printed out when someone uses our REST API to access services that utilize @Transactional. We don’t want the JTA log entries that come from this “polling” MQ listening implementation.
Can you do this?
You should set the default log level higher than DEBUG in your configuration, then try adjusting the log level for
org.springframework.transactionmanually in your REST API inside the appropriate call., e.g.This means that during the call to your API – but only then – the calls initiated by the MQ listener would also be logged, but AFAIK there is no way to configure different log levels for the same class depending on where it is called from 🙁
Update: Another possibility would be to create a custom TransactionManager, which would be just a wrapper for the one provided by Spring. It would forward the calls to Spring and write its own logs. You would use that in your API but the Spring version in the MQ listener. Then you would have two distinct classes, so you could set different log levels. I am fairly sure this is possible, however it may be more hassle to configure and maintain than it is worth…