我有以下logback.xml:
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
</pattern>
</encoder>
</appender>
<appender name="FILE"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>C:/logs/external-web-services.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- daily rollover -->
<fileNamePattern>C:/logs/external-web-services.%d{yyyy-MM-dd}.log
</fileNamePattern>
<maxHistory>30</maxHistory>
</rollingPolicy>
<append>true</append>
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
</pattern>
</encoder>
</appender>
<logger name="org.hibernate.SQL" additivity="false">
<level value="DEBUG" />
<appender-ref ref="FILE" />
</logger>
<logger name="org.hibernate.type" additivity="false">
<level value="DEBUG" />
<appender-ref ref="FILE" />
</logger>
<root level="DEBUG">
<appender-ref ref="STDOUT" />
<appender-ref ref="FILE" />
</root>
我想在我的日志文件中记录Hibernate sql查询。我从Eclipse运行时只在控制台中看到Hibernate查询(也在JBoss日志文件server.log中,但这是我不明白的其他内容)。在我的日志文件(external-web-services.log)中,只打印了我的日志消息。没有打印Hibernate消息。在日食中我得到以下内容:
11:50:05,367 INFO [stdout] (default task-9) Hibernate:
11:50:05,367 INFO [stdout] (default task-9) select
11:50:05,367 INFO [stdout] (default task-9) ftibssettl0_.settlcycleinstanceid as settlcycleinstance1_3_,
11:50:05,367 INFO [stdout] (default task-9) ftibssettl0_.endtime as endtime2_3_,
11:50:05,367 INFO [stdout] (default task-9) ftibssettl0_.PARTSET_0_PART as PARTSET_3_3_,
11:50:05,367 INFO [stdout] (default task-9) ftibssettl0_.PARTSET_1_PART as PARTSET_4_3_,
11:50:05,367 INFO [stdout] (default task-9) ftibssettl0_.PARTSET_2_PART as PARTSET_5_3_,
11:50:05,367 INFO [stdout] (default task-9) ftibssettl0_.PARTSET_3_PART as PARTSET_6_3_,
11:50:05,367 INFO [stdout] (default task-9) ftibssettl0_.PARTSET_4_PART as PARTSET_7_3_,
11:50:05,367 INFO [stdout] (default task-9) ftibssettl0_.settlcycletemplateid as settlcycletemplate8_3_,
11:50:05,368 INFO [stdout] (default task-9) ftibssettl0_.settlementdate as settlementdate9_3_,
11:50:05,368 INFO [stdout] (default task-9) ftibssettl0_.starttime as starttime10_3_,
11:50:05,368 INFO [stdout] (default task-9) ftibssettl0_.status as status11_3_
11:50:05,368 INFO [stdout] (default task-9) from
11:50:05,368 INFO [stdout] (default task-9) ibsprod.FT_IBS_SETTL_CYCLE_INSTANCE ftibssettl0_
11:50:05,368 INFO [stdout] (default task-9) where
11:50:05,368 INFO [stdout] (default task-9) ftibssettl0_.settlementdate=?
11:50:05,417 INFO [stdout] (default task-9) 11:50:05.417 [default task-9] DEBUG g.d.n.s.CashMovementReportService - filterAndMarkCashMovements elapsed time: PT0.017S
这个日志的奇怪之处在于Hibernate消息的格式不是我在logback.xml编码器模式中定义的格式,可以在日志的最后一行看到,这是我的应用程序的日志消息< / p>
其他信息:
我正在使用JBoss所以我需要排除JBoss自己的日志记录子系统以便使用logback工作,我使用的是jboss-deployment-structure.xml文件:
<jboss-deployment-structure>
<deployment>
<exclude-subsystems>
<subsystem name="logging" />
</exclude-subsystems>
</deployment>
</jboss-deployment-structure>
我正在使用JPA,以防这可能有助于这是我的persistence.xml文件:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
version="2.1">
<persistence-unit name="external-ws" transaction-type="JTA">
<description>Oracle Persistence Unit</description>
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>${ds.name}</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="hibernate.default_schema" value="${ds.schema}"/>
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.format_sql" value="true" />
<property name="org.hibernate.flushMode" value="manual"/>
</properties>
</persistence-unit>
答案 0 :(得分:1)
尝试添加:
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>TRACE</level>
</filter>
同时使用CONSOLE和FILE appender。默认阈值是WARN。
您还可以检查这是否是log4j使用的配置文件。由于类加载未命中配置,可能会加载不同的文件。
ch.qos.logback.classic.util.ContextInitializer有一个:
public void configureByResource(URL url) {
您可以尝试在运行时调试以检查实际加载了哪个配置文件的方法。
另外,请尝试删除:
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.format_sql" value="true" />
因为那些只应打印到控制台。