log4j2 混合异步模式配置

一、pom.xml


    org.apache.logging.log4j
    log4j-jcl
    2.11.2


    org.apache.logging.log4j
    log4j-slf4j-impl
    2.11.2


    org.apache.logging.log4j
    log4j-core
    2.11.2


    org.apache.logging.log4j
    log4j-api
    2.11.2


    com.lmax
    disruptor
    3.4.2

注:如果使用异步模式就必需添加disruptor的依赖,因为log4j2的异步模式是基于LMAX Disruptor的(无锁的线程间通信库,而不是队列,可提高吞吐量和降低延时);Log4j-2.9及以上版本需要在之前引用disruptor-3.3.4.jar或更高的版本库;

二、log4j2.xml






	
	
		
		
			
 			
			
		

		
		
			
		
		
		
			
			
			
			
				
				
			
			
			
				
		          
		          
		        
		    
		
		
			
			
			
				
				
			
			
			
		
		
			
			
			
				
				
			
			
		
		
		
	      	    
	        
	

	
		
		
		
		
		
		
		
		
		

		
		
			
		

		
		
		

		
			
			
			
			
		
	

注:

1、info级别日志比较多,所以将Console的级别调整为error,info日志采用异步模式输出到文件,1w条日志信息includeLocation="false"(默认)会比等于“true”时快5倍左右;

2、info级别日志只保留最近60天的;warn和error级别的每个月保存2G左右,未设置定时删除策略;

3、日志输出格式可以在PatternLayout中配置(%C or $class, %F or %file, %l or %location, %L or %line, %M or %method),具体内容参见http://logging.apache.org/log4j/2.x/manual/layouts.html#PatternLayout

你可能感兴趣的:(web)