log4j学习笔记(二)

阅读更多
二、通过配置文件输出日志

1.配置log4j.xml



	
	
		
			
		
	
	
	
		
		
		
			
		
	
	
	
	 	
		
		
		
		
			
		
	
	
		
		
		
			
		
	
	
	
		
		
		
		
		
	
	
	
		
		
	



2.创建应用类log4jtest.LogTest_Config.java
package log4jtest;

import org.apache.log4j.Logger;
import org.apache.log4j.xml.DOMConfigurator;

public class LogTest_Config {

	public static Logger log = Logger.getLogger(LogTest_Config.class);

	public static void main(String[] args) {
		DOMConfigurator.configure("conf/log4j.xml");

		log.debug("debug:");
		log.info("info:");
		log.warn("warn:");
		log.error("error:");
		log.fatal("fatal:");

	}
}


  创建应用类pkg1.AAA.java
package pkg1;

import org.apache.log4j.Logger;
import org.apache.log4j.xml.DOMConfigurator;

public class AAA {

	public static Logger log = Logger.getLogger(AAA.class);

	public static void main(String[] args) {
		DOMConfigurator.configure("conf/log4j.xml");

		log.debug("debug:");
		log.info("info:");
		log.warn("warn:");
		log.error("error:");
		log.fatal("fatal:");

	}
}
  • log4j.jar (349.7 KB)
  • 下载次数: 0

你可能感兴趣的:(log4j,XML,Apache,Java)