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

來源:互聯網
上載者:User
筆記 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


相關文章

Beyond APAC's No.1 Cloud

19.6% IaaS Market Share in Asia Pacific - Gartner IT Service report, 2018

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。