Learning URL 1:http://www.cnblogs.com/licheng/archive/2008/08/23/1274566.html
First, fast start
1. Download log4j compression package, local pressurization
Create a new Java project in the 2.Eclipse development tool, right-click the project select Properties to open the Properties window for the current project, select the Java Build Path >> library (libaries) > > Add an external jar (add External JARs) to add the Log4j.jar package you just downloaded to the project.
3. Create a new Log4j.properties profile in the project: This file is dedicated to configuring log information and its contents determine the output location and format of the log information. Right-click the project select New >> file named Xxx.properties
4. Write the configuration information to the file log4j.properties that you just created:
# # #将日志信息输出到控制台 # # #log4j. appender.stdout=org.apache.log4j.consoleappenderlog4j.appender.stdout.layout= ORG.APACHE.LOG4J.PATTERNLAYOUTLOG4J.APPENDER.STDOUT.LAYOUT.CONVERSIONPATTERN=%D{YYYY-MM-DD HH:mm:ss}%m%n %l %n## #将日志信息输出到文件中 # # #log4j. appender.file=org.apache.log4j.fileappenderlog4j.appender.file.file= sysinfo.loglog4j.appender.file.layout= ORG.APACHE.LOG4J.PATTERNLAYOUTLOG4J.APPENDER.FILE.LAYOUT.CONVERSIONPATTERN=%D{YYYY-MM-DD HH:mm:ss}%m%n %l%n # # #设置日志的优先级别 # # #log4j. rootlogger=debug,stdout,file
5. Create a new Java file to test whether the configuration was successful:
1 ImportOrg.apache.log4j.Logger;2 ImportOrg.apache.log4j.PropertyConfigurator;3 4 Public classLog4jdemo {5 Public Static voidMain (string[] args) {6Logger log =NULL;7 Try {8 //Initialize the log generator, load the log configuration file9Propertyconfigurator.configure ("Log4j.properties");TenLog = Logger.getlogger (Log4jdemo.class. GetName ()); One ALog.debug ("main"); - inti = 1/0; -}Catch(Exception e) { the //Record Log - Log.info (E.getmessage ()); - //e.printstacktrace (); - } + } -}
6. Output results
Ii. Expansion of Learning
Log4j Log Output Learning (Eclipse)