1. Get Log4j.jar Download Log4j.zip address: Http://labs.mop.com/apache-mirror/logging/log4j/1.2.17/log4j-1.2.17.zip decompression Log4j.zip , Get Log4j-1.2.17.jar
2. Rely on Log4j-1.2.17.jar in Eclipse
Right-click the project--build path--Configure build path--libraries-Add External JARs ... --Select log4j-1.2.17.jar--to determine ...
3. Configure Log4j.properties
1. Create a new file in the SRC directory in the project Log4j.properties steps are as follows: Right-click src--new--file--in File Name: Enter log4j.properties---OK ... 2. Add content to Log4j.properties:
Log4j.rootlogger=info, stdout
Log4j.appender.stdout=org.apache.log4j.consoleappender
Log4j.appender.stdout.layout=org.apache.log4j.patternlayout
Log4j.appender.stdout.layout.conversionpattern=%5p [%t] (%F:%l)-%m%n
OK, then you can use, specifically for the care of this configuration, and then analysis
4. New test file Test.java
import Org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
Public class Test {
Static Log log = Logfactory.getlog (Test.class); Public void log () {
Log.debug ("Debug Info.");
Log.info ("info info");
Log.warn ("Warn info");
Log.error ("error info");
Log.fatal ("Fatal info");
}
/**
* @param args
*/
Public Static void Main (string[] args) {
Test test = new test ();
Test.log ();
}
Run and see the results ... OK, you already know how to use the following, let's see why we use this.
—— —— —— EOF —— —— ——
Author: Bi Xiaobong | HTTP://BLOG.CSDN.NET/WIRELESSQA e-mail: wirelessqa.me@gmail.com microblogging: HTTP://WEIBO.COM/WIRELESSQA reprint, please specify the source: Bi Xiaobong-http://blog . CSDN.NET/WIRELESSQA