java Spring hib事务日志

7kqas0il  于 2023-02-11  发布在  Java
关注(0)|答案(3)|浏览(117)

我们如何记录Spring事务机制。我显示了Spring文档第10.5.2节中显示的以下示例。如果我想记录到此级别,如何进行
我正在使用Spring、Hibernate和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)

日志文件..

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
k4aesqcs

k4aesqcs1#

Spring参考中有一节是关于日志的。
它展示了如何配置不同的日志框架,其中包括log4j
在您的情况下,配置的最后一行将是:

log4j.logger.org.springframework.transaction=DEBUG
ecfdbz9o

ecfdbz9o2#

如果您只想设置spring事务支持的日志级别,请尝试向log4j.xml添加以下日志记录器:

<logger name="org.springframework.transaction">
        <level value="DEBUG" />
</logger>
j8ag8udp

j8ag8udp3#

对于hib4和更高版本,您可以用途:

org.hibernate.engine.transaction.internal.TransactionImpl = DEBUB

相关问题