如何在 JBoss Wildfly 9 中关闭 Hibernate 调试日志记录?
Posted
技术标签:
【中文标题】如何在 JBoss Wildfly 9 中关闭 Hibernate 调试日志记录?【英文标题】:How do I turn off Hibernate debug logging in JBoss Wildfly 9? 【发布时间】:2015-10-17 23:15:52 【问题描述】:我正在使用 JBoss Wildfly 9.0.0.CR2。我有一个 Spring 3.2.11.RELEASE web 应用程序,我很好奇如何在我的 $JBOSS_HOME/standalone/log/server.log 文件中关闭 Hibernate 日志记录,特别是所有查询数据,例如
[DEBUG,SQL] select organizati0_.USER_ID as USER_ID1_117_0_, organizati0_.ORGANIZATION_ID as ORGANIZA2_122_0_, organizati1_.id as id1_5_1_, organizati1_.ADDRESS_ID as ADDRESS10_5_1_, organizati1_.COUNTRY_ID as COUNTRY11_5_1_, organizati1_.CREATED_ON as CREATED_2_5_1_, organizati1_.ORGANIZATION_ID as ORGANIZA3_5_1_, organizati1_.IMPLEMENTATION_MANAGER_ID as IMPLEME12_5_1_, organizati1_.IMPORT_DATA_FROM_SIS as IMPORT_D4_5_1_, organizati1_.LTI_REFERER_DOMAIN as LTI_REFE5_5_1_, organizati1_.NAME as NAME6_5_1_, organizati1_.ORGANIZATION_TYPE_ID as ORGANIZ13_5_1_, organizati1_.PARENT_ORGANIZATI
在我的 $JBOSS_HOME/standalone/configuration/standalone.xml 文件中
<subsystem xmlns="urn:jboss:domain:logging:3.0">
<console-handler name="CONSOLE">
<level name="INFO"/>
<formatter>
<named-formatter name="COLOR-PATTERN"/>
</formatter>
</console-handler>
<periodic-rotating-file-handler name="FILE" autoflush="true">
<formatter>
<named-formatter name="PATTERN"/>
</formatter>
<file relative-to="jboss.server.log.dir" path="server.log"/>
<suffix value=".yyyy-MM-dd"/>
<append value="true"/>
</periodic-rotating-file-handler>
<logger category="com.arjuna">
<level name="WARN"/>
</logger>
<logger category="org.apache.tomcat.util.modeler">
<level name="WARN"/>
</logger>
<logger category="org.jboss.as.config">
<level name="DEBUG"/>
</logger>
<logger category="sun.rmi">
<level name="WARN"/>
</logger>
<logger category="jacorb">
<level name="WARN"/>
</logger>
<logger category="jacorb.config">
<level name="ERROR"/>
</logger>
<logger category="org.jasypt">
<level name="DEBUG"/>
</logger>
<logger category="org.springframework">
<level name="ERROR"/>
</logger>
<logger category="org.hibernate">
<level name="ERROR"/>
</logger>
<root-logger>
<level name="INFO"/>
<handlers>
<handler name="CONSOLE"/>
<handler name="FILE"/>
</handlers>
</root-logger>
<formatter name="PATTERN">
<pattern-formatter pattern="%dyyyy-MM-dd HH:mm:ss,SSS %-5p [%c] (%t) %s%e%n"/>
</formatter>
<formatter name="COLOR-PATTERN">
<pattern-formatter pattern="%Klevel%dHH:mm:ss,SSS %-5p [%c] (%t) %s%e%n"/>
</formatter>
</subsystem>
注意我的
<logger category="org.hibernate">
<level name="ERROR"/>
</logger>
没有效果。我的 Web 应用程序中没有 log4j.properties 或 log4j.xml。如何关闭休眠调试?
编辑:
以下是我的实体管理器工厂在 Spring 上下文中的配置方式...
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="packagesToScan" value="org.mainco.subco" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"/>
</property>
<property name="dataSource" ref="dataSource"/>
<property name="jpaPropertyMap" ref="jpaPropertyMap" />
</bean>
<util:map id="jpaPropertyMap">
<entry key="hibernate.show_sql" value="false" />
<entry key="hibernate.hbm2ddl.auto" value="validate"/>
<entry key="hibernate.dialect" value="org.hibernate.dialect.mysql5InnoDBDialect"/>
<entry key="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup" />
<entry key="hibernate.cache.region.factory_class" value="org.hibernate.cache.ehcache.EhCacheRegionFactory"/>
<entry key="hibernate.cache.provider_class" value="org.hibernate.cache.EhCacheProvider"/>
<entry key="hibernate.cache.use_second_level_cache" value="true" />
<entry key="hibernate.cache.use_query_cache" value="false" />
<entry key="hibernate.generate_statistics" value="false" />
</util:map>
<bean id="entityManager" class="org.springframework.orm.jpa.support.SharedEntityManagerBean">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
<jee:jndi-lookup jndi-name="java:jboss/datasources/MySqlDS" id="dataSource" expected-type="javax.sql.DataSource"/>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
:
在我的 WEB-INF/lib 目录中,我有一个 commons-logging-1.1.1.jar,我还链接到 JBoss 的预打包 slf4j 模块(下面是来自 WEB-INF/jboss- 的 sn-p部署结构.xml 文件)...
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2">
<deployment>
<dependencies>
<module name="org.codehaus.jackson.jackson-core-asl" />
<module name="org.codehaus.jackson.jackson-mapper-asl" />
<module name="org.slf4j" />
...
编辑 2:
以下是我想从服务器日志中删除的调试 SQL 前后的一些其他行(我也想删除这些行):
[DEBUG,EntityPrinter] org.mainco.subco.user.domain.UserlastName=test, creator=org.mainco.subco.user.domain.User#ADMIN1, incorrectLogins=null, address=org.mainco.subco.organization.domain.Address#77F7FAC9174A4BCA9A9C5E98F50DD134, userDemographicInfo=null, roles=[org.mainco.subco.user.domain.Role#Instructional Coach], resetState=false, avatar=null, userName=coach, createdOn=2015-07-24 15:39:59.0, enabled=true, url=localhost, firstName=test, temporaryPassword=null, password=V0VW0k+ge+free1My+bS/XSm7qb0ezuvL+irH+A9l5dnMoW0YnZNda2n2Zl138N2BN51MQ==, dob=null, grade=null, organizations=[org.mainco.subco.organization.domain.Organization#6942B22F268A4E66B50C71278E3DAA73], expiration=null, middleName=a, id=5F61E8CA3A554FE1991A05A3E960D442, salutation=null
[DEBUG,EntityPrinter] org.mainco.subco.organization.domain.Organizationcountry=org.mainco.subco.organization.domain.Country#US, address=org.mainco.subco.organization.domain.Address#12946ACF562840458844D8083191CB73, eodbId=104112, parentOrganization=null, sampleOrg=null, createdOn=null, implementationManager=null, url=null, organizationType=org.mainco.subco.organization.domain.OrganizationType#19, userEntered=false, ltiRefererDomain=null, useExternalAuthentication=false, name=Alpine School District, id=6942B22F268A4E66B50C71278E3DAA73, state=org.mainco.subco.organization.domain.State#UT, importDataFromSis=false
[DEBUG,EntityPrinter] org.mainco.subco.organization.domain.OrganizationTypeparent=true, description=Regular District, id=19
[DEBUG,SQL] select user0_.id as id1_117_, user0_.ADDRESS_ID as ADDRESS17_117_, user0_.AVATAR as AVATAR2_117_, user0_.CREATED_ON as CREATED_3_117_, user0_.CREATOR_ID as CREATOR18_117_, user0_.DOB as DOB4_117_, user0_.ENABLED as ENABLED5_117_, user0_.EXPIRATION as EXPIRATI6_117_, user0_.first_name as first_na7_117_, user0_.GRADE_ID as GRADE_I19_117_, user0_.INCORRECT_LOGINS as INCORREC8_117_, user0_.last_name as last_nam9_117_, user0_.middle_name as middle_10_117_, user0_.password as passwor11_117_, user0_.RESET_STATE as RESET_S12_117_, user0_.salutation as salutat13_117_, user0_.temporary_password as tempora14_117_, user0_.url as url15_117_, user0_.USER_DEMOGRAPHIC_INFO_ID as USER_DE20_117_, user0_.user_name as user_na16_117_ from sb_user user0_ where user0_.user_name=? and user0_.url=?
[DEBUG,CriteriaQueryImpl] Rendered criteria query -> select generatedAlias0 from Role as generatedAlias0 where generatedAlias0.name=:param0
【问题讨论】:
你有它打印的消息的例子吗? 是的,这是我问题的第三行——带有“[DEBUG,SQL] selectorganizati0_ ...”的那一行 抱歉,不知道我是怎么错过的 :) 看起来它不是来自 WildFly FWIW。如果在消息的该部分之前有一个时间戳或记录器名称将是有用的。 神秘的是,这就是所有出现的东西——之前没有记录器名称或时间戳。我在 WEB-INF/lib 目录中拥有的唯一日志文件是 commons-logging-1.1.1.jar(没有 log4j)。我链接到 JBoss 的预打包 org.slf4j(包括部署结构)。不知道哪个是罪魁祸首。 是的,默认情况下会添加一个 slf4j API。也许尝试删除 commons-logging jar。目前 WildFly 仅使用 jcl-over-slf4j 进行公共日志记录。 【参考方案1】:尝试在您的standalone.xml 配置中添加以下内容(直接在记录器子系统中):
<use-deployment-logging-config value="false" />
【讨论】:
【参考方案2】:我的问题是我以这种方式解决的控制台,创建了文件:WEB-INF/classes/log4j.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j='http://jakarta.apache.org/log4j/'>
<appender name="CA" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%ddd.MM.yyyy HH:mm:ss %5p (%F:%L) - %m%n" />
</layout>
</appender>
<root>
<level value="info" />
<appender-ref ref="CA" />
</root>
</log4j:configuration>
【讨论】:
【参考方案3】:您应该在 persistence.xml 中设置以下属性
<property name="hibernate.show_sql" value="false" />
【讨论】:
我已经这样做了。我已将我的 Spring/Hibernate 配置添加到我的问题中(注意如何不必使用 persistence.xml)。【参考方案4】:只是猜测:Spring 默认使用org.apache.commons.logging
,这可能是您看到的意外日志消息的原因。
尝试从您的 WAR 中排除 commons-logging
依赖项,将其替换为 WildFly 中包含的 jcl-over-slf4j
模块。
我不确定此模块是否默认导出 - 您可能必须明确声明 module dependency。
【讨论】:
我重新设计了我的应用程序以排除 commons-logging jar,但 Hibernate SQL 消息(以及大量其他内容)仍然存在。【参考方案5】:确保在standalone.xml 中的数据源定义中spy
属性未设置为true
【讨论】:
没有“间谍”属性。数据源外部元素看起来像“以上是关于如何在 JBoss Wildfly 9 中关闭 Hibernate 调试日志记录?的主要内容,如果未能解决你的问题,请参考以下文章
在 Wildfly/Jboss 中部署 ear 期间如何防止 HTTP 404
从 JBoss 7 迁移到 WildFly 9 时使用 CMT 的 EJB
在 JBoss / Wildfly 9 上使用 JAX-RS 项目设置 Swagger.io 问题