灵活控制 Hibernate 的日志或 SQL 输出(包含参数),以便于诊断

首先参考:http://blog.csdn.net/zljjava/article/details/7534349  [灵活控制 Hibernate 的日志或 SQL 输出,以便于诊断]

 

我的具体配置,我的是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="console" class="org.apache.log4j.ConsoleAppender">
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="DP - %d %c%n%-5p: %m%n%n"/>
        </layout>
    </appender>


    <appender name="INFO" class="com.cplatform.log.DatedFileAppender">
        <param name="Encoding" value="UTF-8"/>
        <param name="File" value="${catalina.home}/log/b2c/%yyyy%mm/%dd/info.log"/>
        <param name="Append" value="true"/>
        <param name="BufferedIO" value="false"/>
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d %p %c %t %m%n"/>
        </layout>

    </appender>

    <appender name="ERROR" class="com.cplatform.log.DatedFileAppender">
        <param name="Encoding" value="UTF-8"/>
        <param name="File" value="${catalina.home}/log/b2c/%yyyy%mm/%dd/error.log"/>
        <param name="Append" value="true"/>
        <param name="BufferedIO" value="false"/>
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d %p %c %t %m%n"/>
        </layout>
        <filter class="org.apache.log4j.varia.LevelRangeFilter">
            <param name="LevelMin" value="DEBUG"/>
            <param name="LevelMax" value="FATAL"/>
        </filter>
    </appender>

    <logger name="com.cplatform.b2c">
        <level value="DEBUG"/>
        <appender-ref ref="INFO"/>
    </logger>
    
<!-- ---------------------------------输出Hibernate打印的SQL语句,并且给出?的参数值------------------------------ -->    
<logger name="org.hibernate.type.descriptor.sql.BasicBinder">
     <level value="TRACE"/>
     <appender-ref ref="console"/>
     <appender-ref ref="INFO"/>
</logger>
<!-- 
<logger name="org.hibernate.type.descriptor.sql.BasicExtractor">
     <level value="TRACE"/>
     <appender-ref ref="console"/>
     <appender-ref ref="INFO"/>
</logger> -->
<logger name="org.hibernate.engine.QueryParameters">
     <level value="DEBUG"/>
     <appender-ref ref="console"/>
     <appender-ref ref="INFO"/>
</logger>
<logger name="org.hibernate.engine.query.HQLQueryPlan">
     <level value="DEBUG"/>
     <appender-ref ref="console"/>
     <appender-ref ref="INFO"/>
</logger>
<logger name="org.hibernate.SQL">
         <level value="DEBUG"/>
        <appender-ref ref="console"/>
        <appender-ref ref="INFO"/>
</logger>
<!-- ---------------------------------end------------------------------ -->    

   

    <root>
        <priority value="INFO"/>
        <appender-ref ref="console"/>
        <appender-ref ref="INFO"/>
    </root>
    
    <!-- Application Loggers -->
    <logger name="org.springframework" additivity="false">
        <level value="error" />
    </logger>
    
    <logger name="org.apache" additivity="false">
        <level value="error" />
    </logger>

</log4j:configuration>

 

灵活控制 Hibernate 的日志或 SQL 输出(包含参数),以便于诊断,古老的榕树,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。