我是你妈

编程就好跟打游戏一样,各种攻略,各种副本,各种各种,有意思!

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

首先参考: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>

 

posted on 2014-04-14 10:22  杜兰德  阅读(737)  评论(0编辑  收藏  举报