gpt4 book ai didi

java - Logback RollingFileAppender 不记录 Hibernate 消息

转载 作者:行者123 更新时间:2023-12-01 12:46:33 26 4
gpt4 key购买 nike

我有以下 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 消息。在 Eclipse 中我得到以下信息:

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编码器模式中定义的格式,这可以在日志的最后一行看到,这是我的应用程序的日志消息

其他信息:

我正在使用 JBoss,因此我需要排除 JBoss 自己的日志记录子系统,以便 logback 正常工作,我正在使用文件 jboss-deployment-struct.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>

最佳答案

尝试添加:

<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>TRACE</level>
</filter>

到 CONSOLE 和 FILE 附加器。默认阈值是 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" />

因为这些应该只打印到控制台。

关于java - Logback RollingFileAppender 不记录 Hibernate 消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24649299/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com