Showing a Spring transaction in log Showing a Spring transaction in log java java

Showing a Spring transaction in log


in your log4j.properties (for alternative loggers, or log4j's xml format, check the docs)

Depending on your transaction manager, you can set the logging level of the spring framework so that it gives you more info about transactions. For example, in case of using JpaTransactionManager, you set

log4j.logger.org.springframework.orm.jpa=INFO

(this is the package of the your transaction manager), and also

log4j.logger.org.springframework.transaction=INFO

If INFO isn't enough, use DEBUG


For me, a good logging config to add was:

log4j.logger.org.springframework.transaction.interceptor = trace

It will show me log like that:

2012-08-22 18:50:00,031 TRACE - Getting transaction for [com.MyClass.myMethod]

[my own log statements from method com.MyClass.myMethod]

2012-08-22 18:50:00,142 TRACE - Completing transaction for [com.MyClass.myMethod]


For Spring Boot application with application.properties

logging.level.ROOT=INFOlogging.level.org.springframework.orm.jpa=DEBUGlogging.level.org.springframework.transaction=DEBUG

or if you prefer Yaml (application.yaml)

logging:   level:      org.springframework.orm.jpa: DEBUG      org.springframework.transaction: DEBUG