log4j2.yml in custom module not being pickup by Wildfly

480 views
Skip to first unread message

tom

unread,
Nov 9, 2021, 12:00:51 PM11/9/21
to WildFly
Hi

The application is deployed as EAR file and it is looking up a custom module in wildlfy to load up the properties file, including log4j2.yml.

The log4j2.yml is in a subfolder, say under config folder.

Wildfly does not seem to read the file in the config folder although the web.xml has configured it via web.xml

<context-param>
<param-name>log4jConfiguration</param-name>
<param-value>classpath:/config/log4j2.yml</param-value>
</context-param>

<listener>
<listener-class>org.apache.logging.log4j.web.Log4jServletContextListener</listener-class>
</listener>

If I put the log4j2.yml in the root of the module, then it works fine.

James Perkins

unread,
Nov 9, 2021, 12:23:33 PM11/9/21
to WildFly
What version of WildFly are you using? Also can you post your jboss-deployment-structure.xml.

tom

unread,
Nov 9, 2021, 12:43:17 PM11/9/21
to WildFly
I was testing on Wildlfly 21.

Here's my jboss-deployment-structure.xml in myapp.ear\META-INF\

<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2">
    <deployment>
        <exclude-subsystems>
            <subsystem name="webservices" />
        </exclude-subsystems>
                <dependencies>
            <system export="true">
                <paths>
                    <path name="javax/xml/ws"/>
                    <path name="javax/xml/ws/soap"/>
                    <path name="javax/xml/ws/spi"/>
<path name="javax/xml/ws/spi/http"/>
                    <path name="javax/xml/ws/handler"/>
                    <path name="javax/xml/ws/wsaddressing"/>
                    
                    <path name="javax/jws"/>
                    <path name="javax/jws/soap"/>
                    <path name="com/sun/org/apache/xerces/internal/dom"/>
                    <path name="com/sun/org/apache/xerces/internal/jaxp"/>
                </paths>
            </system>
        </dependencies>
    </deployment>
</jboss-deployment-structure>


Please note that I do have the following in WEB-INF\lib
log4j-api-2.14.1.jar
log4j-core-2.14.1.jar
log4j-web-2.14.1.jar

P.S. When I run my app in Tomcat as a war, it seems to be fine too.

James Perkins

unread,
Nov 9, 2021, 2:21:57 PM11/9/21
to WildFly
You need to add a dependency on the module you created as well. Modules are not automatically added to your deployments modular class loader. Also note with WildFly 22+ you'll need to exclude the `org.apache.logging.log4j.api` module in order to use log4j-core and a log4j2 configuration.

tom

unread,
Nov 9, 2021, 3:41:52 PM11/9/21
to WildFly
Hi, 
I did not create a separate module for log4j2. I am using the jars in the lib folder. Would you please show me the changes that I need in jboss-deployment-structure.xml?

tom

unread,
Nov 10, 2021, 7:31:24 AM11/10/21
to WildFly
Would you please help? I believe log4j2 module was loaded just unable to look for the log4j2 configuration.

tom

unread,
Nov 10, 2021, 1:34:33 PM11/10/21
to WildFly
FYI, I tried the same application in Wildfly 25. The issue is the same. Log4j2 could only be loaded if the log4j2.xml file is in the root folder of the custom module. It is ignoring the log4jconfiguration setting in web.xml

James Perkins

unread,
Nov 11, 2021, 4:28:56 PM11/11/21
to WildFly
What are you referring to as the "custom module"?

tom

unread,
Nov 12, 2021, 7:56:40 AM11/12/21
to WildFly
I created a module under the wildfly modules folder, for example wildfly-25.0.0.Final\modules\com\test\main

It has a subfolder "config" which contains the log4j2.yml

and the module.xml is as follows

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


<module name="com.test" xmlns="urn:jboss:module:1.9">


    <resources>
        <resource-root path="."/>
    </resources>
</module>

James Perkins

unread,
Nov 15, 2021, 10:39:42 AM11/15/21
to WildFly
Then you ned to add the `com.test` module to your deployment. Modules are not loaded as dependencies to a deployment by default.

tom

unread,
Nov 19, 2021, 7:35:35 PM11/19/21
to WildFly
Hi 
It seems to be working only for WAR deployment. Is it the same the EAR?

James Perkins

unread,
Nov 22, 2021, 12:08:23 PM11/22/21
to WildFly
What part does not seem to be working? For an EAR you'd need to add the module to the EAR and each sub-deployment.

tom

unread,
Nov 22, 2021, 2:14:10 PM11/22/21
to WildFly
I added the sub-deployment in jboss-deployment-structure.xml. It created a rolling file in the folder that I specified in the config/log4j2.xml. However, the file is just empty. The log were still written to server.log for some reason.

James Perkins

unread,
Nov 22, 2021, 2:28:22 PM11/22/21
to WildFly
You also need to exclude the org.apache.logging.log4j.api module from each sub-deployment too.

tom

unread,
Nov 22, 2021, 4:11:21 PM11/22/21
to WildFly
I added the following but still not seeing entries in my log file

<sub-deployment name="my.war">
<dependencies>
<module name="com.test" />
</dependencies>
<exclusions>
<module name="org.apache.logging.log4j.api" />
</ exclusions>
</sub-deployment>

tom

unread,
Nov 22, 2021, 4:12:43 PM11/22/21
to WildFly
This is in the server.log. 

108575 [default task-1] INFO stdout  - 16:07:09.109 [default task-1] ERROR com.xxx my error

James Perkins

unread,
Nov 22, 2021, 4:14:28 PM11/22/21
to WildFly
Ah okay. That's because you're using a ConsoleAppender. If you removed the ConsoleAppender from your configuration then it would not go to the server.log.

tom

unread,
Nov 22, 2021, 4:43:55 PM11/22/21
to WildFly
I removed the console appender but still seeing only the entry in server.log

Here's my log4j2.yml. Did I miss anything?

Configuration:
  status: warn

  appenders:
    Console:
      name: LogToConsole
      PatternLayout:
        Pattern: "[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n"

    #File:
    #  name: File
    #  fileName: logs/app.log
    #  PatternLayout:
    #    Pattern: "%d %p %C{1.} [%t] %m%n"

    RollingFile:
      - name: LogToRollingFile
        fileName: c:/logs/app.log
        filePattern: "logs/$${date:yyyy-MM}/app-%d{MM-dd-yyyy}-%i.log.gz"
        PatternLayout:
          pattern: "[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n"
        Policies:
          SizeBasedTriggeringPolicy:
            size: 10MB
        DefaultRollOverStrategy:
          max: 10

  Loggers:
    logger:
      - name: com.xxx
        level: debug
        additivity: false
        AppenderRef:
#          - ref: LogToConsole
          - ref: LogToRollingFile

    Root:
      level: error
      AppenderRef:
        ref: LogToRollingFile

James Perkins

unread,
Nov 22, 2021, 4:50:06 PM11/22/21
to WildFly
What does your jboss-deployment-structure.xml look like and where is it located?

tom

unread,
Nov 22, 2021, 4:52:41 PM11/22/21
to WildFly
in EAR/META-INF/


<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2">
    <deployment>
        <exclude-subsystems>
            <subsystem name="webservices" />
        </exclude-subsystems>
                <dependencies>
<module name="com.test" />
            <system export="true">
                <paths>
                    <path name="javax/xml/ws"/>
                    <path name="javax/xml/ws/soap"/>
                    <path name="javax/xml/ws/spi"/>
<path name="javax/xml/ws/spi/http"/>
                    <path name="javax/xml/ws/handler"/>
                    <path name="javax/xml/ws/wsaddressing"/>
                    
                    <path name="javax/jws"/>
                    <path name="javax/jws/soap"/>
                    <path name="com/sun/org/apache/xerces/internal/dom"/>
                    <path name="com/sun/org/apache/xerces/internal/jaxp"/>
                </paths>
            </system>
        </dependencies>
    </deployment>

<sub-deployment name="my.war">
<dependencies>
<module name="com.test" />
</dependencies>
    <exclusions>
      <module name="org.apache.logging.log4j.api" />
    </exclusions>
</sub-deployment>
</jboss-deployment-structure>

James Perkins

unread,
Nov 22, 2021, 5:52:08 PM11/22/21
to WildFly
One thing is you'll need to exclude the org.apache.logging.log4j.api module on your main (EAR) deployment too. Do you have any other modules besides the web module in your EAR? If so those would need to be listed too. I'm not sure how it will work with servlet initializer either. It might work though. I did a test locally and it did seem to work, but I'm not sure that is guaranteed. 

tom

unread,
Nov 23, 2021, 7:31:14 AM11/23/21
to WildFly
I added the exclusions for module org.apache.logging.log4j.api in main EAR but still did not work. I only have one war file in the ear.

James Perkins

unread,
Nov 23, 2021, 11:08:20 AM11/23/21
to WildFly
Hmm... ...without seeing a specific example I'm not too sure. My test with an EJB and a WAR in an EAR worked. If there is just a WAR in the EAR you could just try using the WAR only as there is no real advantage to the EAR.
Reply all
Reply to author
Forward
0 new messages