1. Overview
Currently, log4j has three development branches: one is the stable version of 1.2, the other is the 1.3 version that has stopped development, and the other is the 2.0 version in the experimental phase. According to the Apache log4j official website, on a computer containing an AMD duron CPU running at MHz and using JDK 1.3.1, log4j 1.2 can complete a log statement in 5 nanoseconds as the log output or not.
2. Download The log4j 1.2 api library
Download from human network lab:
Http://labs.renren.com/apache-mirror//logging/log4j/1.2.16/apache-log4j-1.2.16.zip
Download from bjtu:
Http://mirror.bjtu.edu.cn/apache//logging/log4j/1.2.16/apache-log4j-1.2.16.zip
3. log4j Hello World program source code
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 program running result
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.