1
votes

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.

That's how 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 is:

<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 and the application deployed, 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.

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 this post talking about the same error, based on the answer I thought it might be something wrong the log4j2 version, so I downgrade 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)

Also according to this post, there might be something wrong with log4j2 in Wildfly, so I attempted to tweak around the log4j2 version and configuration, but no luck.

So how to setup the log4j2 in Wildfly8, can anyone help. Thanks a lot in advance.

1
Out of curiosity why slf4j with log4j2? The point of slf4j is not to have to worry about what log manager is being used.James R. Perkins
@Simon got any solution for this ?Sreekanth

1 Answers

0
votes

From all the documentation I can find the EAR's META-INF folder is not in the classpath, so Log4j 2 isn't going to find a configuration file placed there. The only documentation I could find mentioned having to create a module where the common configuration files could be placed.