1

I'm working on a JEE application which uses log4j2 for logging. I'm trying to deploy it on Wildfly 15, but I can't get it to log properly, stating

Log4j2 could not find a logging implementation. Please add log4j-core to the classpath. Using SimpleLogger to log to the console...

Here's what I did:

  • I've added log4j2-api.jar as a system module to Wildfly (system/layers/base/org/apache/log4j2/main) with a simple module.xml.
  • I've taken the code from https://github.com/jboss-logging/log4j2-jboss-logmanager, built a JAR, and added that as a system module to Wildfly (system/layers/base/org/jboss/log4j2/logmanager/main), with a module.xml that defines a provided service:
    <provides>
        <service name="org.apache.logging.log4j.spi.Provider">
            <with-class name="org.jboss.logmanager.log4j.JBossProvider" />
        </service>
    </provides>
  • I've added org.apache.log4j2 and org.jboss.log4j2.logmanager as dependencies to the org.jboss.logmanager module, stating services="export" on the latter.

I'm aware of https://issues.redhat.com/browse/WFCORE-482, but I can't seem to draw the right conclusions from it.

Can anyone help or knows how to diagnose further what's going on here?


For full reference, the module.xml for org.jboss.log4j2.logmanager looks like this:

<module xmlns="urn:jboss:module:1.8" name="org.jboss.log4j2.logmanager">
    <resources>
        <resource-root path="log4j2-jboss-logmanager.jar"/>
    </resources>
    <dependencies>
        <module name="org.apache.log4j2"/>
        <module name="org.jboss.logmanager"/>
    </dependencies>
    <provides>
        <service name="org.apache.logging.log4j.spi.Provider">
            <with-class name="org.jboss.logmanager.log4j.JBossProvider" />
        </service>
    </provides>
</module>

…although i've tried both referencing org.jboss.logmanager as a dependency of org.jboss.log4j2.logmanager and the other way around.

The module.xml for org.apache.log4j2 looks like this:

<module xmlns="urn:jboss:module:1.1" name="org.apache.log4j2">
    <resources>
        <resource-root path="log4j-api.jar"/>
    </resources>
</module>
stmoebius
  • 662
  • 11
  • 30
  • What does your `module.xml` files look like? They should look something like https://github.com/jamezp/wildfly-core/commit/cabcf5c71ef2815c8442d7eda6d1e63930adf248#diff-a20c1b8d1398b3f2b8d531a1d04fd8c1 and https://github.com/jamezp/wildfly-core/commit/cabcf5c71ef2815c8442d7eda6d1e63930adf248#diff-85d8592708d89a62bd8844cb0429edc2. – James R. Perkins May 19 '20 at 15:10
  • Why would the org.jboss.log4j2.logmanager module depend on org.jboss.logmanager, instead of the other way around? From where would the org.jboss.log4j2.logmanager module be referenced? That seems to be the part that I don't understand. – stmoebius May 19 '20 at 15:51
  • Added both module.xml above and tried both log4j2.logmanager depending on logmanager and the other way around, with the same result. – stmoebius May 19 '20 at 16:04
  • Because the `org.jboss.log4j2.logmanager` requires the `org.jboss.logmanager` not the other way around. – James R. Perkins May 19 '20 at 19:02

1 Answers1

1

In your org.jboss.log4j2.logmanager module.xml you don't need that <provides/> definition. Other than that your module.xml files look correct.

Next you'll need to define both the org.jboss.log4j2.logmanager and org.apache.log4j2 modules on your deployment. If you're using a jboss-deployment-structure.xml it would look something like the following for a WAR:

<jboss-deployment-structure>
    <deployment>
        <dependencies>
            <module name="org.apache.log4j2"/>
            <module name="org.jboss.log4j2.logmanager" export="true"/>
        </dependencies>
    </deployment>
</jboss-deployment-structure>

One minor note is those should probably live directly under the modules directory and not the modules/system/layers/base directory. Though it doesn't break anything that is really meant for modules provided by the server.

James R. Perkins
  • 16,800
  • 44
  • 60
  • Thanks. This is working fine as long as I start Wildfly from the command line, using standalone.bat. As soon as I use a service wrapper (Tanuki), it breaks down. I don't have a deployment structure descriptor, and I'm using an EAR. No matter which way I tweak classpath, jboss.modules.system.pkgs, global-modules (standalone.xml), module definitions and dependencies, I can't get this to work. What happens is that the MSC service thread loads EJBs from JARs in the EAR, and in its context it can see the log4j2-api, but not the JBossProvider. Any ideas? – stmoebius May 25 '20 at 14:10
  • You definitely don't want to use `jboss.modules.system.pkgs`. You're best bet is either a `jboss-deployment-structure.xml` or the `Dependencies:` entry in your manifest file. – James R. Perkins May 26 '20 at 14:44
  • With the global-modules make sure you try with `meta-inf="true"` on the `org.jboss.log4j2.logmanager` module too. – James R. Perkins May 26 '20 at 14:53