Java Log Service getting started series of tutorials-(2) Apache log4j getting started

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.