1.log4j有三種主要組件:logger、appender and layout2.Log4j提供的appender有以下幾種:org.apache.log4j.ConsoleAppender(控制台)org.apache.log4j.FileAppender(文件)org.apache.log4j.DailyRollingFileAppender(每天產生一個日志文件)org.apache.log4j.RollingFileAppender(文件大小到達指定尺寸的時候產生一個新的文件)org.apache.log4j.WriterAppender(將日志信息以流格式發送到任意指定的地方)3.Log4j提供的layout有以下幾種:org.apache.log4j.HTMLLayout(以Html表格形式布局)org.apache.log4j.PatternLayout(可以靈活地指定布局模式)org.apache.log4j.SimpleLayout(包含日志信息的級別和信息字符串)org.apache.log4j.TTCCLayout(包含日志產生的時間、線程、類別等等信息)4.Log4j提供的幾種輸出格式:%M:Used to output the method name where the logging request was issued.%m:Used to output the application supplied message associated with the logging event.%l:Used to output location information of the caller which generated the logging event%L:Used to output the line number from where the logging request was issued.%p:Used to output the priority of the logging event.%n:Outputs the platform dependent line separator character or characters. %r:Used to output the number of milliseconds elapsed since the start of the application until the creation of the logging event.%F:Used to output the file name where the logging request was issued.%d:Used to output the date of the logging event. %c:Used to output the category of the logging event%C:Used to output the fully qualifIEd class name of the caller issuing the logging request5.如果是對於效率要求比較高的話,要在log.debug()之前加上log.isDebugEnabled()進行判斷,這樣能夠大大減少執行時間6.對於各個appenders,共有的屬性是layout(一般設置為org.apache.log4j.PatternLayout),Threshold(Log的級別)(1)ConsoleAppender:Target(System.out和System.err)(2)FileAppender:File(定義輸出的文件名),Append(定義是否為追加)(3)DailyRollingFileAppender(除FileAppender屬性外):MaxFileSize(最大文件大小),MaxBackupIndex()
必要的時候可以參考一下:http://dev.csdn.Net/develop/article/62/62201.shtm