gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 07:52:36 30 4
gpt4 key购买 nike

根据要求和出于安全目的,我正在更新 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 文件夹中添加了相关的库。请提出任何建议。

最佳答案

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.

引导日志框架需要文件 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.

关于java - 错误 StatusLogger 找不到 log4j2 配置文件。在更新Struts 2.5.12版本时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45647599/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com