1. 程式人生 > >java log4j.xml配置

java 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="[%p] %d{yyyy-MM-dd HH:mm:ss} %l: %m%n" />
<param name="ConversionPattern" value="[%-d{HH:mm:ss}][adp] %p [%t] %c{1}.%M(%L) | %m%n"/>  
</layout>
</appender> -->

<!-- 檔案輸出日誌 org.apache.log4j.FileAppender(不分天,下面分天)-->
<appender name="FILE-LOG" class="org.apache.log4j.DailyRollingFileAppender">
<param name="Threshold" value="warn" />
<param name="File" value="/var/log/webapps/app_catalina.log" />
<!-- <param name="DatePattern" value="app_catalina_'yyyy-MM-dd'.log" /> -->
<param name="Append" value="true" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern"
value="%d{yyyy-MM-dd HH:mm:ss} [%p] [%t] [%l] %m%n" />
</layout>
</appender>




<!-- spring -->
<logger name="org.springframework" additivity="false">
<level value="error" />
<appender-ref ref="console" />
</logger>

<!-- struts2 -->
<logger name="org.apache.struts2" additivity="false">
<level value="error" />
<appender-ref ref="console" />
</logger>

<!-- ibatis -->
<logger name="com.ibatis" additivity="true">
<level value="error" />
</logger>

<!-- ibatis連線 -->
<logger name="java.sql.Connection" additivity="true">
<level value="error" />
</logger>

<!-- ibatis編譯 -->
<logger name="java.sql.Statement" additivity="true">
<level value="error" />
</logger>

<!-- ibatis顯示預編譯sql日誌 -->
<logger name="java.sql.PreparedStatement" additivity="true">
<level value="error" />
<appender-ref ref="console" />
</logger>

<!-- ibatis顯示結果集日誌 -->
<logger name="java.sql.ResultSet" additivity="true">
<level value="error" />
<appender-ref ref="console" />
</logger>

<root>
<level value="warn" />
<!-- <appender-ref ref="console" /> -->
<appender-ref ref="FILE-LOG" />
</root>
</log4j:configuration>