源碼:apache
<appender name="STDOUT" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss} %c%n -- %p -- %m%n" />
</layout>
</appender>app
若是使用pattern佈局就要指定的打印信息的具體格式ConversionPattern,打印參數以下:佈局
<!--
%m 輸出代碼中指定的消息
%p 輸出優先級,即DEBUG,INFO,WARN,ERROR,FATAL
%r 輸出自應用啓動到輸出該log信息耗費的毫秒數
%c 輸出所屬的類目,一般就是所在類的全名
%t 輸出產生該日誌事件的線程名
%n 輸出一個回車換行符,Windows平臺爲「rn」,Unix平臺爲「n」
%d 輸出日誌時間點的日期或時間,默認格式爲ISO8601,也能夠在其後指定格式,好比:%d{yyyy MMM dd HH:mm:ss,SSS},輸出相似:2002年10月18日 :10:28,921
%l 輸出日誌事件的發生位置,包括類目名、發生的線程,以及在代碼中的行數。線程
%x Used to output the NDC (nested diagnostic context) associated with the thread that generated the logging event
%X Used to output the MDC (mapped diagnostic context) associated with the thread that generated the logging event for specified key
-->日誌
示例:事件
log4j.appender.R.layout.ConversionPattern=%d{yyyy-MMM-dd HH:mm:ss,SSS}-[TS] %p %t %c - %m%nci
輸出:2012-06-06 10:45:30,000-[TS] INFO thread30 TestClass - 記錄的日誌源碼