0 Replies Latest reply on Apr 12, 2016 9:19 PM by Simon Liu

    How to setup Log4j2 in Wildfly 8.2

    Simon Liu Newbie

      I am using slf4j via log4j2 (version 2.5) for an ear application (includes ejb and web app) which is deployed to Wildfly 8.2 server.

       

      The parent POM looks like:

      <dependencyManagement>

          <dependencies>

              <!-- SLF4J -->

              <dependency>

                  <groupId>org.slf4j</groupId>

                  <artifactId>slf4j-api</artifactId>

                  <version>${slf4j-version}</version>

              </dependency>

              <dependency>

                  <groupId>org.apache.logging.log4j</groupId>

                  <artifactId>log4j-bom</artifactId>

                  <version>${log4j2-version}</version>

                  <scope>import</scope>

                  <type>pom</type>

              </dependency>

              ...

          </dependencies>

      </dependencyManagement>

       

      And the modules' pom.xml

      <dependencies>

          <dependency>

              <groupId>org.slf4j</groupId>

              <artifactId>slf4j-api</artifactId>

          </dependency>

          <dependency>

              <groupId>org.apache.logging.log4j</groupId>

              <artifactId>log4j-slf4j-impl</artifactId>

          </dependency>

          <dependency>

              <groupId>org.apache.logging.log4j</groupId>

              <artifactId>log4j-core</artifactId>

          </dependency>

          ...

      </dependencies>

       

      Then I placed the log4j2.xml into the ear's META-INF folder

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

          <Configuration status="DEBUG"> 

              <Appenders> 

                 <File name="FileLogger" fileName="app-simple.log"> 

                    <PatternLayout pattern="%d{HH:mm:ss} [%t] %-5level %logger{3} - %m%n"/> 

                 </File> 

              </Appenders> 

              <Loggers> 

                 <Root level="DEBUG"> 

                    <AppenderRef ref="FileLogger"/> 

                 </Root> 

              </Loggers> 

          </Configuration>

       

       

      After all these done, nothing really happened, no error, the log file was not generated either.

       

      I thought the Wildfly logging subsystem might interfere with it. So I added the jboss-deployment-structure.xml in the META-INF folder to exclude the Wildfly's logging

       

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

          <jboss-deployment-structure>

              <deployment>

                  <exclude-subsystems>

                      <subsystem name="logging"/>

                  </exclude-subsystems>

              </deployment>

          </jboss-deployment-structure>

       

       

      and then I got the following error,  actually the configuration file is in place.

          15:07:20,648 ERROR [stderr] (MSC service thread 1-5) ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console.

       

      I did find the post from stackoverflow talking about the same error, based on the answer I thought it might be something wrong the log4j2 version, so I downgraded the version to 2.0.1, and then it didn't complain about the configuration file but gave this new error:

          16:57:38,456 ERROR [stderr] (MSC service thread 1-5) ERROR StatusLogger Could not search jar file 'C:\Servers\wildfly-8.2.0.Final\standalone\deployments\test-ear.ear\lib\log4j-core.jar\org\apache\logging\log4j\core' for classes matching criteria: annotated with @Plugin file not found java.io.FileNotFoundException: C:\Servers\wildfly-8.2.0.Final\standalone\deployments\test-ear.ear\lib\log4j-core.jar\org\apache\logging\log4j\core (The system cannot find the path specified)


      It looked like there are some issues with log4j2 and Wildfly 8.2, and I attempted to tweak around the log4j2 version and configuration, but no luck.

       

      Can anyone help. Thanks a lot in advance.