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