如何在JBoss Wildfly 9中关闭Hibernate调试日志记录?

时间:2015-07-27 16:41:52

标签: hibernate logging jboss wildfly

我正在使用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="%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%c] (%t) %s%e%n"/>
        </formatter>
        <formatter name="COLOR-PATTERN">
            <pattern-formatter pattern="%K{level}%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%e%n"/>
        </formatter>
    </subsystem>

请注意我的

        <logger category="org.hibernate">
            <level name="ERROR"/>
        </logger>

无效。我的Web应用程序中没有log4j.properties或log4j.xml。如何关闭Hibernate调试?

修改

以下是我在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&#39;预先打包的slf4j模块(下面是WEB-INF / jboss-deployment-structure.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.User{lastName=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.Organization{country=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.OrganizationType{parent=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

5 个答案:

答案 0 :(得分:1)

尝试在standalone.xml配置中添加以下内容(直接在记录器子系统中):

        <use-deployment-logging-config value="false" />

答案 1 :(得分:0)

您应该在persistence.xml中设置以下属性

 <property name="hibernate.show_sql" value="false" />

答案 2 :(得分:0)

猜测:Spring默认使用org.apache.commons.logging,它可能会导致您看到的意外日志消息。

尝试从WAR中排除commons-logging依赖项,将其替换为WildFly中包含的jcl-over-slf4j模块。

我不确定默认情况下是否导出此模块 - 您可能必须明确声明module dependency

答案 3 :(得分:0)

确保standalone.xml内的数据源定义中的spy属性未设置为true

答案 4 :(得分:0)

我的问题是控制台我这样解决了,创建了文件: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="%d{dd.MM.yyyy HH:mm:ss} %5p (%F:%L) - %m%n" />
        </layout>
    </appender>

    <root>
        <level value="info" />
        <appender-ref ref="CA" />
    </root>
</log4j:configuration>