当前位置: 首页 > 知识库问答 >
问题:

log4j2错误StatusLogger无法识别的转换说明符

郭云
2023-03-14
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 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.

xml配置。log4j2.version=2.10.0,Spring Boot版本为1.5.9

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-logging</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.7.25</version>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-slf4j-impl</artifactId>
        <version>${log4j2.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-api</artifactId>
        <version>${log4j2.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-core</artifactId>
        <version>${log4j2.version}</version>
    </dependency>
</dependencies>
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>3.1.0</version>
            <configuration>
                <createDependencyReducedPom>false</createDependencyReducedPom>
            </configuration>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <transformers>
                            <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>
                        </transformers>
                        <filters>
                            <filter>
                                <artifact>*:*</artifact>
                                <excludes>
                                    <exclude>META-INF/*.SF</exclude>
                                    <exclude>META-INF/*.DSA</exclude>
                                    <exclude>META-INF/*.RSA</exclude>
                                </excludes>
                            </filter>
                        </filters>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
    </plugins>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
        </resource>
    </resources>
    <sourceDirectory>src/main/java</sourceDirectory>
</build>

log4j2.xml配置

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="debug" monitorInterval="30" shutdownHook="disable">
    <properties>
        <property name="LOG_HOME">/data1/logs</property>
        <property name="JOB_NAME">noname</property>
    </properties>
    <Appenders>
        <Console name="Console" target="SYSTEM_OUT">
            <PatternLayout pattern="%date{yyyy-MM-dd HH:mm:ss} [%t] %level [%logger{36}][%file:%line] %msg%n%throwable"/>
        </Console>

        <RollingRandomAccessFile name="DetailFile"
                                 fileName="${sys:LOG_HOME}/${sys:JOB_NAME}/detail.log" bufferedIO="false"
                                 filePattern="${sys:LOG_HOME}/${sys:JOB_NAME}/detail.%d{yyyy-MM-dd}-%i.log">

            <PatternLayout
                    pattern="%date{yyyy-MM-dd HH:mm:ss} [%t] %level [%file:%line] %msg%n%throwable"/>
            <Policies>
                <TimeBasedTriggeringPolicy interval="1" modulate="true"/>
                <SizeBasedTriggeringPolicy size="500 MB"/>
            </Policies>
        </RollingRandomAccessFile>
        <RollingRandomAccessFile name="error"
                                 fileName="${sys:LOG_HOME}/${sys:JOB_NAME}/error.log" bufferedIO="true"
                                 filePattern="${sys:LOG_HOME}/${sys:JOB_NAME}/error.%d{yyyy-MM-dd}.log">

            <PatternLayout
                    pattern="%date{yyyy-MM-dd HH:mm:ss} [%t] %level [%logger{36}:%line] %msg%n%throwable"/>
            <Policies>
                <TimeBasedTriggeringPolicy interval="1" modulate="true"/>
            </Policies>
        </RollingRandomAccessFile>
    </Appenders>
    <Loggers>
        <Root level="info">
            <AppenderRef ref="DetailFile"/>
            <AppenderRef level="error" ref="error"/>
        </Root>
    </Loggers>
</Configuration>

共有1个答案

蒯卓君
2023-03-14

如果依赖项包含log4j2插件,则JAR中包含log4j2plugins.dat缓存文件。当使用Maven shade插件将多个JAR与log4j2plugins.dat文件合并时,只有一个可以存活。如果没有插件定义,则在启动时会显示错误。Log4j2问题

一个解决方案是从阴影jar中排除log4j2plugins.dat缓存文件,这样Log4j就可以在启动时扫描插件。为此,在POM的maven-shade-plugin配置中添加一个过滤器:

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>3.1.0</version>
        <configuration>
            <createDependencyReducedPom>false</createDependencyReducedPom>
            <filters>
                <filter>
                    <artifact>*:*</artifact>
                    <excludes>
                        <exclude>**/Log4j2Plugins.dat</exclude>
                    </excludes>
                </filter>
            </filters>
        </configuration>
        ...
    </plugin>

另一个解决方案是使用特定于log4j版本的转换插件合并缓存文件。

 类似资料:
  • Spring 4.3.30 hibernate 5应用程序。pom.xml具有所有log4j2依赖项。 甚至增加了log4j2.xml 我得到的错误是: 我还错过了什么,因为即使我的模式不包含默认布局,我也一直在出错?我在迁移到log4j之前使用log4jlog4j2.Din计划迁移到log4j2,但由于我必须升级Spring和hibernate,我开始找到ERROR StatusLogger N

  • 我有一个运行在Tomcat 8上的web应用程序的log4j2配置文件,如下所示 我看到我的 Web 应用写入日志文件,但我对线程名称的 %t 模式似乎无法解析,因此我收到这样的日志语句 请注意,我得到%t而不是线程名称 所以为了解决这个问题,我使用选项启动了Tomcat 当webapp正在部署和log4j2正在初始化时,我看到catalina.out中打印出以下消息。 我的web应用程序包含以下

  • 我有一个用Java编写的AWS Lambda函数。我想用一个自定义的GraalVM运行时来运行Lambda函数,例如在这篇博客文章中所做的 每当应用程序启动时,我都会收到以下错误: 这是我的log4j2.xml文件的样子 这里的其他类似问题表明,这是由于fatjar中存在冲突的log4j包。基于这个答案中的建议,我现在使用shadowJar和一个转换来构建fatjar,GraalVM应用程序就是从

  • 我正在尝试在我的Geb框架中设置log4j2。就我的一生而言,我不知道如何把这些结合起来。我有一个log4j2。使用记录器“Selenium”设置xml(不是log4j.xml)文件。在DefaultPage中,我尝试从配置文件。 log4j2.xml DefaultPage.groovy 测试执行并将输出写入STDERR,这是预期的,因为我有记录器。错误但是,它不支持日期的格式。此外,我还使用其

  • 错误StatusLogger找不到log4j2配置文件。使用默认配置:只将错误记录到控制台。将系统属性“org.apache.logging.log4j.simplelog.statuslogger.level”设置为TRACE,以显示Log4j2内部初始化日志记录。 解决此问题的方法: 2.增加内容

  • 有了,我可以使用表示