错误 StatusLogger 找不到 log4j2 配置文件。在更新 Struts 的 2.5.12 版本时

ERROR StatusLogger No log4j2 configuration file found. While updating the version 2.5.12 of Struts

根据要求和出于安全目的,我正在更新 Struts 项目。 Struts之前的版本是2.3.24,现在更新到2.5.12。我已经下载了 Struts 的所有必需的 jar 文件并应用于项目,但我收到以下错误

ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console. Set system property 'org.apache.logging.log4j.simplelog.StatusLogger.level' to TRACE to show Log4j2 internal initialization logging.

但是我没有在我的项目中使用任何记录器。我已经添加了所有的依赖 jar 文件,我没有使用 Maven,而是在 lib 文件夹中添加了相关的库。有什么建议吗

No log4j2 configuration file found 表示 log4j2.xml 配置文件不在您的类路径中。

检查您的项目 jar 是否包含 log4j confuguration file

否则,您可以在构建脚本中将 log4j 配置文件路径设置为系统 属性。

<sysproperty key="log4j.configurationFile" value="file:///${basedir}/src/log4j2.xml" />

检查 https://logging.apache.org/log4j/2.x/manual/configuration.html log4j 配置

Struts 框架正在使用日志框架 log4j 第二版。

Struts 2.3 to 2.5 migration

Please be aware that the framework is using Log4j2 now as a main logging layer, the existing old logging layer is deprecated and will be removed soon. Log4j2 supports many different logging implementations, please check documentations for more details.

bootstrap 日志框架需要文件 log4j2.xml。但是类路径中缺少它。 Struts 框架中也缺少它。


您应该找到一些 log4j2.xml,即来自 struts-showcase 应用程序或阅读本教程中的第 4 步 How To Create A Struts 2 Web Application

Step 4 - Add Logging

To see what’s happening under the hood, the example application for this tutorial uses log4j2. You’ll need to add a dependency node for log4j2 to the pom:

pom.xml log4j dependency node

<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-core</artifactId>
    <version>2.8.2</version>
</dependency>
<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-api</artifactId>
    <version>2.8.2</version>
</dependency>

Using both log4j-core and log4j-api allows to use the latest version of Log4j2 without a clash with version provided by the framework. Setup a log4j2.xml configuration in the src/main/resources folder which contains the following

log4j2.xml

<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
    <Appenders>
        <Console name="STDOUT" target="SYSTEM_OUT">
            <PatternLayout pattern="%d %-5p [%t] %C{2} (%F:%L) - %m%n"/>
        </Console>
    </Appenders>
    <Loggers>
        <Logger name="com.opensymphony.xwork2" level="debug"/>
        <Logger name="org.apache.struts2" level="debug"/>
        <Root level="warn">
            <AppenderRef ref="STDOUT"/>
        </Root>
    </Loggers>
</Configuration>

Note the above log4j2 configuration specifies the console as the log target.