Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring hibernate Transaction Logging

how can we log spring Transaction mechanism. i am showing below example shown in Spring Doc sec 10.5.2.if i want to logging upto this level how to do that

i am using Spring,Hibernate and Log4j.

<!-- the Spring container is starting up... -->
[AspectJInvocationContextExposingAdvisorAutoProxyCreator] - Creating implicit proxy
for bean 'fooService' with 0 common interceptors and 1 specific interceptors
<!-- the DefaultFooService is actually proxied -->
[JdkDynamicAopProxy] - Creating JDK dynamic proxy for [x.y.service.DefaultFooService]
<!-- ... the insertFoo(..) method is now being invoked on the proxy -->
[TransactionInterceptor] - Getting transaction for x.y.service.FooService.insertFoo
<!-- the transactional advice kicks in here... -->
[DataSourceTransactionManager] - Creating new transaction with name    [x.y.service.FooService.insertFoo]
[DataSourceTransactionManager] - Acquired Connection
[org.apache.commons.dbcp.PoolableConnection@a53de4] for JDBC transaction
<!-- the insertFoo(..) method from DefaultFooService throws an exception... -->
[RuleBasedTransactionAttribute] - Applying rules to determine whether transaction should
rollback on java.lang.UnsupportedOperationException
[TransactionInterceptor] - Invoking rollback for transaction on x.y.service.FooService.insertFoo
due to throwable [java.lang.UnsupportedOperationException]

<!-- and the transaction is rolled back (by default, RuntimeException instances cause rollback) -->
[DataSourceTransactionManager] - Rolling back JDBC transaction on Connection
[org.apache.commons.dbcp.PoolableConnection@a53de4]
[DataSourceTransactionManager] - Releasing JDBC Connection after transaction
[DataSourceUtils] - Returning JDBC Connection to DataSource

Exception in thread "main" java.lang.UnsupportedOperationException
at x.y.service.DefaultFooService.insertFoo(DefaultFooService.java:14)
<!-- AOP infrastructure stack trace elements removed for clarity -->
at $Proxy0.insertFoo(Unknown Source)

Logging File..

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
log4j.rootLogger=info, stdout
log4j.category.org.springframework.transactions=DEBUG  
like image 559
Vish Avatar asked May 05 '11 13:05

Vish


2 Answers

There's a section about Logging in the Spring Reference.

It shows how to configure different logging frameworks, among them log4j

In your case the last line of the config would be:

log4j.logger.org.springframework.transaction=DEBUG
like image 145
Sean Patrick Floyd Avatar answered Sep 23 '22 06:09

Sean Patrick Floyd


If you're just willing to set the log level of spring transaction support, try adding the following logger to your log4j.xml :

<logger name="org.springframework.transaction">
        <level value="DEBUG" />
</logger>
like image 25
Lucas de Oliveira Avatar answered Sep 22 '22 06:09

Lucas de Oliveira