Log4j2报错ERROR StatusLogger Unrecognized format specifier

问题

使用maven-shade-plugin或者maven-assembly-plugin插件把项目打成一个可执行JAR包时,如果你引入了log4j2会出现如下问题:

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.

解决方法

pom中添加如下配置。

<plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-shade-plugin</artifactId>
   <version>2.4.3</version>
   <executions>
       <execution>
           <phase>package</phase>
           <goals>
               <goal>shade</goal>
           </goals>
           <configuration>
               <filters>
                   <filter>
                       <artifact>*:*</artifact>
                       <excludes>
                           <exclude>META-INF/*.SF</exclude>
                           <exclude>META-INF/*.DSA</exclude>
                           <exclude>META-INF/*.RSA</exclude>
                       </excludes>
                   </filter>
               </filters>
               <finalName>${artifactId}-${env}-${version}</finalName>
               <transformers>
                   <transformer
                           implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                       <mainClass>xxx.yyyy.zzz.Main</mainClass>
                   </transformer>
                   <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                       <resource>META-INF/spring.handlers</resource>
                   </transformer>
                   <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                       <resource>META-INF/spring.schemas</resource>
                   </transformer>
                   <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                       <resource>META-INF/spring.tooling</resource>
                   </transformer>
                   <transformer
                           implementation="org.apache.maven.plugins.shade.resource.ComponentsXmlResourceTransformer"/>
                   <transformer
                           implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
                   <transformer implementation="com.github.edwgiz.mavenShadePlugin.log4j2CacheTransformer.PluginsCacheFileTransformer" />
               </transformers>
           </configuration>
       </execution>
   </executions>
   <dependencies>
       <dependency>
           <groupId>com.github.edwgiz</groupId>
           <artifactId>maven-shade-plugin.log4j2-cachefile-transformer</artifactId>
           <version>2.6.1</version>
       </dependency>
   </dependencies>
</plugin>

原因分析

log4j2 是采用的插件式编程,当log4j2包编译时,或者含有log4j2插件的包编译时,会将需要加载的插件信息放在META-INF/org/apache/logging/log4j/core/config/plugins/Log4j2Plugins.dat这个文件中(包括官方logj42的原生插件),然后项目启动的时候,log4j2会在各个jar包的META-INF目录下扫描这个插件信息文件,然后去加载插件。

但是当项目被打成一个jar包时,如果两个不同的jar包中都有Log4j2Plugins.dat 这个文件,就会出现问题,其中一个文件会被另一个覆盖,导致项目启动的时候有一个文件中的插件不能被正常加载,导致报错。

解决这个问题就是当所有jar包被打成一个jar包时,需要对各个jar包中的Log4j2Plugins.dat进行合并,这就是maven-shade-plugin.log4j2-cachefile-transformer这个包所做的事情了。

原文地址:https://www.cnblogs.com/yeyang/p/10485790.html

时间: 2024-10-10 09:56:47

Log4j2报错ERROR StatusLogger Unrecognized format specifier的相关文章

log4j报错ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console.

ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console. log4j版本:log4j-core-2.7.jar   log4j-api-2.7.jar log4j2只支持xml和json两种格式的配置,所以配置log4j.properties时,是没有作用的. log4j 2.0与以往的1.x有一个明显的不同,其配置

在WSL中安装swool报错 error: unrecognized command line option &#39;-V&#39; 的解决方法

Windows Subsystem for Linux Ubuntu中使用pecl安装swool时遇到错误"error: C compiler cannot create executables"."error: unrecognized command line option '-V'" 解决方法 先看解决方法, 将gcc版本降低到4.8即可,因为高版本gcc取消了-V参数: sudo apt install gcc-4.8 -y sudo update-alte

源码安装mysql5.6x启动报错:[ERROR] Can&#39;t find messagefile &#39;/data/mysqldata/3306/english/errmsg.sys&#39;

170502 10:43:40 mysqld_safe Starting mysqld daemon with databases from /data/mysqldata/3306/data 2017-05-02 10:43:40 0 [Warning] The syntax '--language/-l' is deprecated and will be removed in a future release. Please use '--lc-messages-dir' instead.

git push报错error: failed to push some refs to &#39;[email&#160;protected]:

$ git push -u origin master To [email protected]:xxx/xxx.git ! [rejected] master -> master (fetch first) error: failed to push some refs to '[email protected]:xxx/xxx.git' hint: Updates were rejected because the remote contains work that you do hint:

Mysql多实例进入db报错ERROR 2002

今天做了mysql多实例实验, 进入3307没问题 进入3306: 进入: mysql -S /data/3306/mysql.sock报错: ERROR 2002 (HY000):Can't connect to local MySQL server 解决: 1. kill 33934 kill 34228 2, 我把启动脚本mysql中的密码去掉了 我把启动脚本mysql 统统chmod +x处理(之前是700) 3,重启 mysqld_safe --defaults-file=/data/

安装MySQL-python报错error: command &#39;gcc&#39; failed with exit status 1

[[email protected] MySQL-python-1.2.3]# python setup.py install function) .... _mysql.c:133: error: 'ER_SYNTAX_ERROR' undeclared (first use in this function) _mysql.c:380: error: '_mysql_ConnectionObject' has no member named 'connection' _mysql.c:382

真机测试报错ERROR/AndroidRuntime: java.lang.RuntimeException: setParameters failed解决办法

这个错误是和调用相机摄像头相关的. 产生这个错误的原因主要在于代码控制分辨率的显示和真机测试分辨率不一样. 一:解决办法 WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); Camera.Parameters parameters = camera.getParameters();// 得到摄像头的参数 para

升级到macOS 10.12 mysqlb报错ERROR 1045 (28000): Access denied for user &#39;root&#39;@&#39;localhost&#39; (using password: NO)

系统升级到macOS 10.12后启动mysql后,在终端输入mysql 报错ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES/NO) 解决办法1 在系统偏好设置里关闭mySQL2 $ cd /usr/bin3 $ sudo mysqld_safe --skip-grant-tables4 再打开一个终端$ mysqlmysql> use mysql;mysql> UPDATE

升级 MySQL 至 5.5,报错 [ERROR] Plugin &#39;InnoDB&#39; init function returned error

MySQL 从 5.5 升级到 5.6,启动时报错: [ERROR] Plugin 'InnoDB' init function returned error. [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed. [ERROR] Unknown/unsupported storage engine: InnoDB [ERROR] Aborting 原因:主要是没有正常关闭 mysqld 服务的情况下,对数据库参数进行改