Log4j.xml学習
7338 ワード
ログは各プロジェクトにおいて非常に重要な地位を占めており、プログラムが実行する各プロセスを記録することができ、プロジェクトの実行状態を観察したり、エラーの位置を特定したりするのに便利です.
参照先:
http://www.haogongju.net/art/954653
http://shwenwen.itpub.net/post/34911/527019
<!DOCTYPE log4j:configuration PUBLIC "-//APACHE//DTD LOG4J 1.2//EN" "log4j.dtd">
<appender name="file" class="org.apache.log4j.DailyRollingFileAppender">
<param name="File" value="/data/app/statistics-image/log/count.log" />
<param name="DatePattern" value="'.'yyyy-MM-dd" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern"
value="[%d{yyyy-MM-dd HH:mm:ss,SSS}] [%t] %-5p %c %x - %m%n" />
</layout>
</appender>
<root>
<level value="info" />
<appender-ref ref="CONSOLE" />
<appender-ref ref="file" />
</root>
<category name="java.sql">
<priority value="debug" />
</category>
<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
<param name="Target" value="System.out" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern"
value="[%d{yyyy-MM-dd HH:mm:ss,SSS}] [%t] %-5p %c %x - %m%n" />
</layout>
</appender>
</log4j:configuration>
<!-- ========================== ================================ -->
<!-- %p , DEBUG,INFO,WARN,ERROR,FATAL -->
<!-- #%r log -->
<!-- #%c , -->
<!-- #%t -->
<!-- #%n ,Windows “\r
”,Unix “
” -->
<!-- #%d , ISO8601, , :%d{yyy MMM dd HH:mm:ss,SSS}, :2002 10 18 22:10:28,921 -->
<!-- #%l , 、 , 。 :Testlog4.main(TestLog4.java:10) -->
<!-- ========================================================================== -->
<!-- ========================== ================================ -->
<!-- Log4j appender : -->
<!-- org.apache.log4j.ConsoleAppender( ), -->
<!-- org.apache.log4j.FileAppender( ), -->
<!-- org.apache.log4j.DailyRollingFileAppender( ), -->
<!-- org.apache.log4j.RollingFileAppender( ), -->
<!-- org.apache.log4j.WriterAppender( ) -->
<!-- ========================================================================== -->
<!-- -->
<appender name="filelog_appender"
class="org.apache.log4j.RollingFileAppender">
<!-- File : -->
<param name="File" value="log/testlog4jxml_all.log" />
<!-- , -->
<param name="Append" value="true" />
<!-- -->
<param name="MaxFileSize" value="1MB" />
<!-- -->
<param name="MaxBackupIndex" value="10000" />
<!-- -->
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss} %-5p (%c:%L)- %m%n" />
</layout>
</appender>
<!-- -->
<appender name="filelog_daily" class="org.apache.log4j.DailyRollingFileAppender">
<param name="File" value="log/daily.log" />
<param name="DatePattern" value="'daily.'yyyy-MM-dd'.log'" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="[%d{yyyy-MM-dd HH:mm:ss\} %-5p] [%t] (%c:%L) - %m%n" />
</layout>
</appender>
<!-- -->
<appender name="console" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern"
value="%d{yyyy-MM-dd HH:mm:ss} %-5p: %m%n" />
<!-- "%-5p: [%t] [%c{3}.%M(%L)] | %m%n" -->
</layout>
</appender>
<appender name="EMAIL_QQ" class="org.apache.log4j.net.SMTPAppender">
<param name="Threshold" value="INFO"/>
<param name="BufferSize" value="128" />
<param name="SMTPHost" value="smtp.qq.com" />
<param name="SMTPUsername" value="cjjvictory" />
<param name="SMTPPassword" value="***" />
<param name="From" value="[email protected]" />
<param name="To" value="[email protected]" />
<param name="Subject" value=" " />
<param name="LocationInfo" value="true" />
<param name="SMTPDebug" value="true" />
<layout class="org.cjj.log4j.extend.PatternLayout_zh">
<param name="ConversionPattern" value="[%d{ISO8601}] %-5p %c %m%n"/>
</layout>
</appender>
<!--- , appender -->
<appender name="ASYNC_test" class="org.apache.log4j.AsyncAppender">
<param name="BufferSize" value="10"/>
<appender-ref ref="EMAIL_QQ"/>
</appender>
<!-- -->
<category name="org.cjj" additivity="false">
<!-- , 5 , , ERROR , -->
<level value="ERROR" />
<appender-ref ref="filelog_daily" />
<appender-ref ref="daily_appender" />
<appender-ref ref="console" />
<appender-ref ref="ASYNC_test" />
</category>
参照先:
http://www.haogongju.net/art/954653
http://shwenwen.itpub.net/post/34911/527019