WildFly 8和Log4j 2的log4j-web模块 [英] WildFly 8 and Log4j 2’s log4j-web module
问题描述
我正在运行在WildFly上运行的Web应用程序,该应用程序使用SLF4J和Log4j 2作为日志记录系统.在有关Log4j 2的Apache页面上,我了解了在Web应用程序中使用log4j-web模块的优点(在Web应用程序中使用Log4j 2 ),所以我添加了它,此后WildFly拒绝了部署(这就是为什么我在下面的清单中将其注释掉了.) >
所以,这是我的问题:是否建议在WildFly中使用log4j-web模块?如果是,如何设置它以与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-structure.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>
Log4j2 2.1
及更高版本会出现wildFly 8.x.
Log4j2 2.0.2
没有此错误,但还有其他阻止程序错误(LOG4J2-832)
I am working on a web application that is running on WildFly and that is using SLF4J and Log4j 2 as logging system. On the Apache pages about Log4j 2 I read about the advantages of using the log4j-web module in a web application (Using Log4j 2 in Web Applications), so I added it and since then WildFly refuses the deployment (that is why I have commented it out in the listing below).
So, here is my question: is it advisable to use the log4j-web module with WildFly and if so, how do I set it up to work with WindFly?
Here are relevant listings:
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-structure.xml
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
<deployment>
<exclude-subsystems>
<subsystem name="logging"/>
</exclude-subsystems>
</deployment>
</jboss-deployment-structure>
Parent 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>
Backend 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>
This is a common bug with wildfly 8.x
, and there is a fix only for wildfly 9.x
Log4j2 2.1
onward will have deployment error with wildFly 8.x.
Log4j2 2.0.2
does not have this error but have other blocker bug (LOG4J2-832)
这篇关于WildFly 8和Log4j 2的log4j-web模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!