slf4j log4j配置 log4j过滤

阅读更多

slf4j log4j配置

 

1.需要的jar包:

log4j-api-2.0-rc2.jar

log4j-core-2.0-rc2.jar

log4j-slf4j-impl-2.0.jar

slf4j-api-1.6.4.jar

 

下载路径:http://mvnrepository.com/artifact/org.apache.logging.log4j

 

2.配置文件:log4j2.xml   放在src下(编译后自动复制到classes下)




	
		D:\\log\\proxy
		
		{LOG_HOME}/backup
		stat
		global
	
	
		
		
			  
				
			    
			    
			    
			    
			    
			    
			  
			
		
		
			
			
			
				
				
			
			
		
		
			
			
			
				
				
			
			
		
		
			
			
			
		
	
	
		
		
			
			
		
		
			
			
		
		
			
			
		
		
		
	

 

 

 以上注释为个人理解。

官方文档:http://logging.apache.org/log4j/2.x/manual/appenders.html

 

3. java实现:类名:TestServlet

 

package com.dahantc.test;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@WebServlet("/TestServlet")
public class TestServlet extends HttpServlet {

	private static Logger logger = LoggerFactory.getLogger(TestServlet.class);
	private static final long serialVersionUID = -6795168385294556128L;

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doPost(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		logger.info("===============sss进入==============");
		PrintWriter _write = resp.getWriter();
		_write.print("22");
		_write.flush();
		_write.close();
		logger.info("========end=======");
	}

}

 

你可能感兴趣的:(slf4j,log4j2配置,log4j2过滤包,log4j2重复输出)