JavaLog Service入門系列教程——(2)Apache log4j入門

來源:互聯網
上載者:User

1. 概述

目前log4j有三個發展分支,一個是1.2的穩定版,一個是已經停止繼續發展的1.3版本,另一個就是實驗階段的2.0版本。Apache log4j官網上稱,在一台載有運行在800MHz的AMD Duron CPU並使用JDK 1.3.1 上的電腦中,log4j 1.2 只需要5納秒就可以完成一個日誌語句是應該作為日誌輸出還是不輸出的決定。

2. 下載log4j 1.2 API library

從人人網的實驗室下載:

http://labs.renren.com/apache-mirror//logging/log4j/1.2.16/apache-log4j-1.2.16.zip

從BJTU下載:

http://mirror.bjtu.edu.cn/apache//logging/log4j/1.2.16/apache-log4j-1.2.16.zip

3. log4j的Hello World 程式原始碼

package com.sinosuperman.log4j;import org.apache.log4j.BasicConfigurator;import org.apache.log4j.Logger;public class Test {private static final Logger logger = Logger.getLogger(Test.class);public static void main(String[] args) {BasicConfigurator.configure();logger.info("Hello World, This is an information message.");logger.error("Hello World, This is a error message.");logger.warn("Hello World, This is a warning message.");logger.debug("Hello World, This is a debugging message.");logger.fatal("Hello World, This is a fatal message.");System.exit(0);}}

4. log4j的Hello World 程式運行結果

1 [main] INFO com.sinosuperman.log4j.Test  - Hello World, This is an information message.3 [main] ERROR com.sinosuperman.log4j.Test  - Hello World, This is a error message.3 [main] WARN com.sinosuperman.log4j.Test  - Hello World, This is a warning message.3 [main] DEBUG com.sinosuperman.log4j.Test  - Hello World, This is a debugging message.3 [main] FATAL com.sinosuperman.log4j.Test  - Hello World, This is a fatal message.

聯繫我們

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

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

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.