gpt4 book ai didi

java - WildFly 8 和 Log4j 2 的 log4j-web 模块

转载 作者:太空宇宙 更新时间:2023-11-04 14:10:04 30 4
gpt4 key购买 nike

我正在开发一个在 WildFly 上运行的 Web 应用程序,该应用程序使用 SLF4J 和 Log4j 2 作为日志记录系统。在有关 Log4j 2 的 Apache 页面上,我了解到在 Web 应用程序中使用 log4j-web 模块的优点 ( Using Log4j 2 in Web Applications ),因此我添加了它,从那时起 WildFly 拒绝部署(这就是我在下面的列表中将其注释掉的原因)。

所以,我的问题是:是否建议将 log4j-web 模块与 WildFly 一起使用?如果是,我该如何设置它以与 WindFly 一起使用?

以下是相关列表:

webapp\WEB-INF\classes\log4j2.xml

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

<Configuration status="WARN">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</Console>
<File name="File" fileName="myFile.log">
<PatternLayout pattern="%d{yyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</File>
</Appenders>
<Loggers>
<Root level="DEBUG">
<AppenderRef ref="Console"/>
<AppenderRef ref="File"/>
</Root>
</Loggers>
</Configuration>

webapp\WEB-INF\jboss-deployment-struct.xml

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

<jboss-deployment-structure>
<deployment>
<exclude-subsystems>
<subsystem name="logging"/>
</exclude-subsystems>
</deployment>
</jboss-deployment-structure>

父pom.xml

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

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>

*snip*

<properties>
<java.version>1.8</java.version>
<slf4j.version>1.7.10</slf4j.version>
<log4j.version>2.1</log4j.version>
<maven.plugin.compiler.version>3.2</maven.plugin.compiler.version>

<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencyManagement>
<dependencies>
<!-- SLF4J -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>

<!-- Apache Log4j API -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${log4j.version}</version>
</dependency>

<!-- Apache Log4j SLF4J Binding -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>${log4j.version}</version>
</dependency>

<!-- Apache Log4j Core -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j.version}</version>
</dependency>
</dependencies>
</dependencyManagement>

*snip*

</project>

后端pom.xml

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

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>

*snip*

<dependencies>
<!-- SLF4J -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>

<!-- Apache Log4j API -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
</dependency>

<!-- Apache Log4j SLF4J Binding -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
</dependency>

<!-- Apache Log4j Core -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
</dependency>
</dependencies>
</project>

WebApp pom.xml

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

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>

*snip*

<properties>
<servlet.version>3.1.0</servlet.version>

<maven.plugin.war.version>2.6</maven.plugin.war.version>
<maven.plugin.wildfly.version>1.0.2.Final</maven.plugin.wildfly.version>
</properties>

<dependencyManagement>
<dependencies>
<!-- Backend dependency -->
<dependency>
*snip*
</dependency>

<!-- Apache Log4j Web -->
<!--<dependency>-->
<!--<groupId>org.apache.logging.log4j</groupId>-->
<!--<artifactId>log4j-web</artifactId>-->
<!--<version>${log4j.version}</version>-->
<!--<scope>runtime</scope>-->
<!--</dependency>-->

<!-- Java Servlet API -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>${servlet.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<!-- Backend dependency -->
<dependency>
*snip*
</dependency>

<!-- Apache Log4j Web -->
<!--<dependency>-->
<!--<groupId>org.apache.logging.log4j</groupId>-->
<!--<artifactId>log4j-web</artifactId>-->
<!--</dependency>-->

<!-- Java Servlet API -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
</dependency>
</dependencies>

<build>
<pluginManagement>
<plugins>
<!-- Maven WAR Plugin -->
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>${maven.plugin.war.version}</version>
</plugin>

<!-- WildFly Maven Plugin -->
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<version>${maven.plugin.wildfly.version}</version>

<configuration>
<!-- Server credentials from Maven's settings.xml -->
<id>WildFlyServer</id>
</configuration>
</plugin>
</plugins>
</pluginManagement>

<plugins>
<!-- WildFly Maven Plugin -->
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

最佳答案

这是一个common bugwildfly 8.x 一起使用,并且仅针对 wildfly 9.x

进行了修复

Log4j2 2.1 及以上版本在 wildFly 8.x 中会出现部署错误。

Log4j2 2.0.2 没有此错误,但有其他阻止程序错误 (LOG4J2-832)

关于java - WildFly 8 和 Log4j 2 的 log4j-web 模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28438228/

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