0
votes

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>
1
What does your module.xml files look like? They should look something like github.com/jamezp/wildfly-core/commit/… and github.com/jamezp/wildfly-core/commit/….James R. Perkins
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
Added both module.xml above and tried both log4j2.logmanager depending on logmanager and the other way around, with the same result.stmoebius
Because the org.jboss.log4j2.logmanager requires the org.jboss.logmanager not the other way around.James R. Perkins

1 Answers

0
votes

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.