错误状态记录器无法识别的格式说明符

2ledvvac  于 2021-07-14  发布在  Java
关注(0)|答案(1)|浏览(548)

Spring4.3.30+Hibernate5应用程序。xml具有所有log4j2依赖项。

<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-jcl</artifactId>
    <version>${log4j2.version}</version>
  </dependency>
  <dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-core</artifactId>
    <version>${log4j2.version}</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-1.2-api</artifactId>
    <version>${log4j2.version}</version>
  </dependency>
  <dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-to-slf4j</artifactId>
    <version>${log4j2.version}</version>
  </dependency>

甚至添加了log4j2.xml

<?xml version="1.0" encoding="UTF-8" ?>
  <Configuration status="TRACE">

  <Appenders>
    <Console name="Console" target="SYSTEM_OUT">
      <PatternLayout pattern="%p [%t] %c{1}.%M(%L) | %m%n"/>
    </Console>
  </Appenders>
  <Loggers>
    <Root level="INFO">
      <AppenderRef ref="Console"/>
    </Root>
  </Loggers>

</Configuration>

我得到的错误是:

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.

即使我的模式不包含默认的布局,但是当我不断出现上述错误时,我还缺少什么呢?在迁移到log4j2之前,我使用的是log4j。我不打算迁移到log4j2,但是由于我必须升级spring和hibernate,我开始得到error statuslogger找不到log4j2配置文件。这时我决定迁移到log4j2。

dzjeubhm

dzjeubhm1#

首先,让我们列出您的依赖项及其作用:
log4jcl为apachecommons日志记录提供了一个实现,将这些日志记录调用路由到log4j2。
log4j核心是log4j2实现。
log4j-slf4j-impl使用slf4j api将日志记录调用路由到log4j 2。
log4japi是log4j2api。
log4j-1.2-api将使用log4j 1.x进行的日志记录调用路由到log4j 2。
log4j-to-slf4j将日志记录调用从log4j 2api路由到slf4j。
如果从描述中不清楚,第6项将是一个问题。首先,现在有了log4j 2api的两个实现:log4j核心和log4j到slf4j。如果log4j-to-slf4j是一个“赢”的人,那么你最终会因为log4j-to-slf4j之间的呼叫会跳转,然后又会跳转回来而无处登录。
然而,若这些都在pom的dependencymanagement部分,那个将是一个不同的故事,因为它所做的只是声明您想要使用哪个版本的jar。
至于您看到的错误,这是因为log4j的核心插件由于某种原因没有被加载。如果您将所有内容着色到一个jar中,并且没有包含log4j的log4jplugins.dat文件,则可能会发生这种情况。

相关问题