1

I'm using Log4j2(2.17.1) with two type of configs(log4j.prop & log4j2.xml) on multiple projects. My APP's log4j2 works properly on Tomcat 9 while reading external log4j config. But somehow it stops working or only logging into server.log when I deploy my APP onto JBoss EAP 7. So I think the problem is coming from JBoss, and I need a way to tell it don't mess with my own Log4j2. Does anyone know how to do it?

user6309529
  • 153
  • 1
  • 3
  • 16

2 Answers2

1

With JBoss EAP 7.4 there is a new module which delegates the log4j-api logs to the jboss-logmanager. If you want to use the log4j log manager (log4j-core) then you need to exclude some modules from your deployment.

Option 1 below I would say is preferred since it only affects a single deployment. Option 2 will affect all deployments.

Option 1

Add a jboss-deployment-structure.xml to your deployment:

<jboss-deployment-structure>
  <deployment>
    <exclusions>
        <module name="org.apache.logging.log4j.api" />
    </exclusions>
  </deployment>
</jboss-deployment-structure>

Option 2

Change the add-logging-api-dependencies attribute in the logging subsystem to false.

CLI example:

/subsystem=logging:write-attribute(name=add-logging-api-dependencies, value=false)
James R. Perkins
  • 16,800
  • 44
  • 60
  • Tried option 1 and it did stopped logging into server log, but still not writing log to where it have to be after APP read my external log4j.xml. I'll try option 2 later. – user6309529 Jan 12 '22 at 10:39
  • If option 1 works you'll see the same result with option 2. Do you use a log4j-api as your logging facade in your application? – James R. Perkins Jan 12 '22 at 15:15
  • Yeah, and log4j-1.2api too since many of my app were upgraded from log4j1 – user6309529 Jan 13 '22 at 07:53
  • any other way to solve this? I tried to exclude logging subsystem in jboss deployment file, but I still cannot get it working while using external log4j config. So I have to put the log4j config file back into WEB-INF/classes due to I cannot solve it. – user6309529 Jan 17 '22 at 07:57
  • That would be specific to log4j. Maybe something here would help https://logging.apache.org/log4j/2.x/manual/configuration.html. – James R. Perkins Jan 17 '22 at 16:32
  • I was upgrading an application from JBoss EAP 7.1 to 7.4 and observed the exception "java.lang.NoSuchMethodError: org.apache.logging.log4j.spi.LoggerContextFactory.isClassLoaderDependent()Z" in the server log. I followed Option 1 and added an exclusion for the module "org.apache.logging.log4j.api" to the jboss-deployment-structure.xml file, and this solved the issue. Thanks! – gburgalum01 Aug 01 '22 at 20:37
0

The root cause for this issue is related to the "ClassLoader" which is searched by JBoss EAP Logging in order to find the appropriate logging provider implementation. This search is made in the following order:

  1. JBoss EAP LogManager
  2. Log4j
  3. Slf4j
  4. JDK logging

Since both JBoss EAP LogManager and Log4j2 are available in the classpath, the JBoss EAP LogManager will be utilized due to the "higher precedence". For this reason, you must set the use-deployment-logging-config=false in the logging subsystem. Furthermore, the JBoss EAP LogManager also uses classes from Log4j2 in its own implementation. That's why the modules, org.apache.log4j and org.apache.commons.logging have to be excluded from the deployment in order for Log4J2 to work correctly.

  • The log manager in JBoss EAP, JBoss Log Manager, does not have any relationship with log4j or log4j 2. In JBoss EAP 7.4 the log4j-api (log4j 2) is supported and has an implementation that writes log4j logs to the jboss-logmanager. However, the log manager itself has no knowledge of log4j or log4j2. – James R. Perkins Jan 10 '22 at 16:32