4

我在 Spring 3.5 容器中使用 JpaTransactionManager 和休眠 3。我无法为 JPA 启用日志记录。我希望查看用于调试我的一些服务的事务管理日志。我正在使用 log4j。

这是我的 log4j.properties 中的内容

# For JPA
log4j.logger.org.springframework.orm.jpa=DEBUG
log4j.logger.org.springframework.orm.jpa.JpaTransactionManager=DEBUG
log4j.logger.org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter=DEBUG
log4j.logger.org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean=DEBUG
log4j.logger.org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor=DEBUG
log4j.logger.org.springframework.transaction=DEBUG
log4j.logger.org.springframework=DEBUG
log4j.logger.org.hibernate=DEBUG
log4j.logger.org.hibernate.SQL=DEBUG

# Redirect log messages to a log file
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=C:\\apps\application.log
log4j.appender.file.MaxFileSize=1MB
log4j.appender.file.MaxBackupIndex=5
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n

# Direct log messages to stdout
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

# Root logger option
log4j.rootLogger=ALL, file
4

2 回答 2

4

事务日志可以通过以下方式具体设置log4j.properties

log4j.logger.org.springframework.orm.jpa.JpaTransactionManager=DEBUG

在此上下文中感兴趣的其他日志:

log4j.logger.org.hibernate.transaction=DEBUG
log4j.logger.org.springframework.transaction=DEBUG
于 2016-02-22T12:19:02.433 回答
0

在为 JPATransactionManager 启用日志记录方面,这对我有用: 1. 下载 logback jars (logback-classic-1.0.1.jar, logback-core-1.0.1.jar) 并放入类路径。由于我使用的是 SLF4J,所以我也有 log4j-over-slf4j-1.6.4.jar 和 slf4j-api-1.6.4.jar。2. 使用以下 logback.xml(在 WEB-INF/classes 中)进行配置:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="stdout" class="ch.qos.logback.core.ConsoleAppender">
    <encoder>
        <pattern>
            %d %p [%c] - &lt;%m&gt;%n
        </pattern>
    </encoder>
    <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
        <level>DEBUG</level>
    </filter>
</appender>

<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>${catalina.home}/logs/application.log</file>
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
        <fileNamePattern>${catalina.home}/logs/application-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
        <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
            <maxFileSize>20MB</maxFileSize>
        </timeBasedFileNamingAndTriggeringPolicy>
    </rollingPolicy>

    <encoder>
        <pattern>
            %d %p [%c] - &lt;%m&gt;%n
        </pattern>
    </encoder>
    <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
        <level>ALL</level>
    </filter>
</appender>

<logger name="org.hibernate.transaction.JDBCTransaction" level="DEBUG"/>
<logger name="org.hibernate.jdbc.ConnectionManager" level="DEBUG"/>
<logger name="org.springframework.orm.jpa.JpaTransactionManager" level="DEBUG"/>

<root level="ERROR">
    <appender-ref ref="FILE"/>
</root>
</configuration>
于 2012-04-23T14:56:08.277 回答