栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Log4j2 升级到2.17.1踩过的坑

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Log4j2 升级到2.17.1踩过的坑

目录

1. 如果你用的是spring boot2.x 怎么升级方便

2. Caused by: java.lang.NoSuchMethodError: com.lmax.disruptor.dsl.Disruptor

3. Log4j2 error- ERROR StatusLogger Unrecognized format specifier

版本

LibraryCurrentUpgraded
Lo4j2 related jar*2.17.1

1. 如果你用的是spring boot2.x 怎么升级方便

在pom.xml里加log4j2.version属性, 覆盖掉spring-boot-starter-parent的指定版本。

	
		org.springframework.boot
		spring-boot-starter-parent
		2.6.2
		 
	
     
	
      2.17.1

原因是: 

spring-boot-dependendencies.pom里定义了 log4j2.version属性,利用它的值加的log4j2相关的包。

.... 
 org.springframework.boot
  spring-boot-dependencies
  2.6.2
  pom
...
  
...
    2.17.0
    1.2.9
    1.18.22
    1.7.32
...
  

    
      
        org.apache.logging.log4j
        log4j-bom
        ${log4j2.version}
        pom
        import
      
     

在 log4j-bom.pom 里其实它把所有的log4j相关包都加了。所以在我们的项目你直接用就可以了。

  org.apache.logging.log4j
  log4j-bom
....
  
    
      
      
        org.apache.logging.log4j
        log4j-api
        ${project.version}
      
      
      
        org.apache.logging.log4j
        log4j-core
        ${project.version}
      
        .....
      
      
        org.apache.logging.log4j
        log4j-1.2-api
        ${project.version}
      
      
      
        org.apache.logging.log4j
        log4j-jcl
        ${project.version}
      
      
      
        org.apache.logging.log4j
        log4j-slf4j-impl
        ${project.version}
      
      
      
        org.apache.logging.log4j
        log4j-slf4j18-impl
        ${project.version}
      
      
      
        org.apache.logging.log4j
        log4j-to-slf4j
        ${project.version}
      
  
      
      
        org.apache.logging.log4j
        log4j-web
        ${project.version}
      

      
      
        org.apache.logging.log4j
        log4j-jul
        ${project.version}
      
      ....
    
  

如果你不是很了解 import的含义,可以看看下面的介绍,讲的很清楚

Maven – Introduction to the Dependency Mechanism

2. Caused by: java.lang.NoSuchMethodError: com.lmax.disruptor.dsl.Disruptor

异常信息:

Caused by: java.lang.NoSuchMethodError: com.lmax.disruptor.dsl.Disruptor.(Lcom/lmax/disruptor/EventFactory;ILjava/util/concurrent/ThreadFactory;Lcom/lmax/disruptor/dsl/ProducerType;Lcom/lmax/disruptor/WaitStrategy;)V

原因:

项目使用了log4j2,由于使用了全局异步打印日志的方式,还需要引入disruptor的依赖


     com.lmax
      disruptor
     3.2.0

log4j2.xml

	
		
		 
			
		
	

解决方法:

升级Disruptor 到3.4.0 版本


     com.lmax
      disruptor
     3.4.0

3. Log4j2 error- ERROR StatusLogger Unrecognized format specifier

错误信息:

ERROR StatusLogger Unrecognized format specifier [d]
ERROR StatusLogger Unrecognized conversion specifier [d] starting at position 16 in conversion pattern.
ERROR StatusLogger Unrecognized format specifier [thread]
ERROR StatusLogger Unrecognized conversion specifier [thread] starting at position 25 in conversion pattern.
ERROR StatusLogger Unrecognized format specifier [level]
ERROR StatusLogger Unrecognized conversion specifier [level] starting at position 35 in conversion pattern.
ERROR StatusLogger Unrecognized format specifier [logger]
ERROR StatusLogger Unrecognized conversion specifier [logger] starting at position 47 in conversion pattern.
ERROR StatusLogger Unrecognized format specifier [msg]
ERROR StatusLogger Unrecognized conversion specifier [msg] starting at position 54 in conversion pattern.
ERROR StatusLogger Unrecognized format specifier [n]
ERROR StatusLogger Unrecognized conversion specifier [n] starting at position 56 in conversion pattern.
ERROR StatusLogger Reconfiguration failed: No configuration found for '135fbaa4' at 'null' in 'null'

相关代码- pom.xml


				org.apache.maven.plugins
				maven-shade-plugin				
				
					
						package
						
							shade
						
						
							your-component-name
						
					
				
			

解决方法:

打包的时候去掉Log4j2Plugins.dat 文件。


				org.apache.maven.plugins
				maven-shade-plugin				
				
					
						package
						
							shade
						
						
							your-component-name
                             
								  	
                                	*:*
                                	
	                                    **/Log4j2Plugins.dat 
                                	
                            	
							
						
					
				
			

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/731955.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号