欢迎您访问365答案网,请分享给你的朋友!
生活常识 学习资料

Log4j2升级到2.17.1踩过的坑

时间:2023-07-07

目录

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

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

3、Log4j2 error- ERROR StatusLogger Unrecognized format specifier

版本

LibraryCurrentUpgradedLo4j2 related jar*2.17.1

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

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

org.springframework.bootspring-boot-starter-parent2.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.pluginsmaven-shade-pluginpackageshadeyour-component-name

解决方法:

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

org.apache.maven.pluginsmaven-shade-pluginpackageshadeyour-component-name *:* **/Log4j2Plugins.dat

Copyright © 2016-2020 www.365daan.com All Rights Reserved. 365答案网 版权所有 备案号:

部分内容来自互联网,版权归原作者所有,如有冒犯请联系我们,我们将在三个工作时内妥善处理。