程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> JAVA編程 >> 關於JAVA >> 今天總算看完了log4j,心情不錯!把自己的學習筆記拿出來給大家共享一把

今天總算看完了log4j,心情不錯!把自己的學習筆記拿出來給大家共享一把

編輯:關於JAVA

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

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved