[Common Java tools]-log4j 1: log4j Quick Start

Source: Internet
Author: User
1. Obtain log4j. Jar

  • Download address of log4j.zip: http://labs.mop.com/apache-mirror/logging/log4j/1.2.17/log4j-1.2.17.zip
  • Decompress log4j.zip to get the log4j-1.2.17.jar

2. Dependency log4j-1.2.17.jar in eclipse
  • Right-click Project -- Build path -- configure build path -- libraries -- add external jars .. -- select log4j-1.2.17.jar -- OK...

3. Configure log4j. Properties

1. create the log4j file in the src directory of the project. properties step: Right-click SRC -- New -- file -- In File Name: Enter log4j. properties --- OK... 2. in log4j. properties:
Log4j. rootlogger = info, Stdout
Log4j. appender. stdout = org. Apache. log4j. leleappender
Log4j. appender. stdout. layout = org. Apache. log4j. patternlayout
Log4j. appender. stdout. layout. conversionpattern = % 5 p [% T] (% F: % L)-% m % N
OK. You can use it later. configure it as needed and analyze it later.
4. Create a test file named test. java.

ImportOrg. Apache. commons. Logging. log;

ImportOrg. Apache. commons. Logging. logfactory;

Public ClassTest
{

StaticLogLog=
Logfactory.Getlog(Test.Class);

Public VoidLog (){

Log. Debug ("Debug
Info .");

Log. Info ("info
Info ");

Log. Warn ("warn
Info ");

Log. Error ("error
Info ");

Log. Fatal ("fatal
Info ");

}

/**

*@ ParamARGs

*/

Public Static VoidMain (string []
ARGs ){

Test test =NewTest ();

Test. Log ();

}

}

Run and check the result... OK. You already know how to use it. Let's see why it is used ..

-- EOF ------

Author: Bi Xiaopeng |Http://blog.csdn.net/wirelessqaEmail:Wirelessqa.me@gmail.comWeibo: http://weibo.com/wirelessqa reprint please indicate the source: Bi Xiaopeng-Http://blog.csdn.net/wirelessqa

Related Article

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.