0

I have an web application which uses slf4j with log4j. It is deployed on Wildfly 9. Unfortunately, I have to use a third-party library which reconfigures log4j programatically. It is calling PropertyConfigurator.configure();, it is not possible to use log4j-over-slf4j. As per doc:

The log4j-over-slf4j module will not work when the application calls log4j components that are not present in the bridge. For example, when application code directly references log4j appenders, filters or the PropertyConfigurator, then log4j-over-slf4j would be an insufficient replacement for log4j.

I tried to put the jars into a jboss-module, but the library still changes my configuration. Is it possible with modules to isolate the logging functionality of the library from the one of the web application? Or somehow else?

edit: I also tried to use different classloaders (using a custom log4j) (by using a jboss-deployment-structure.xml)

<?xml version="1.0"?>
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2">
 <deployment>
    <exclusions>
      <module name="org.apache.log4j" slot="main"/>
    </exclusions>
  </deployment>
</jboss-deployment-structure>

and using the wildfly-provided log4j in the module, but then i get the following errors when the library tries to configure its log4j:

20:51:32,719 ERROR [stderr] (default task-1) log4j:ERROR A "org.apache.log4j.RollingFileAppender" object is not assignable to a "org.apache.log4j.Appender" variable. 20:51:32,721 ERROR [stderr] (default task-1) log4j:ERROR The class "org.apache.log4j.Appender" was loaded by 20:51:32,723 ERROR [stderr] (default task-1) log4j:ERROR [ModuleClassLoader for Module "org.jboss.log4j.logmanager:main" from local module loader @66d1af89 (finder: local module finder @8646db9 (roots: D:\wildfly-9.0.2.Final\modules,D:\wildfly-9.0.2.Final\modules\system\layers\base))] whereas object of type 20:51:32,725 ERROR [stderr] (default task-1) log4j:ERROR "org.apache.log4j.RollingFileAppender" was loaded by [ModuleClassLoader for Module "deployment.my-application-1.0.0-SNAPSHOT.war:main" from Service Module Loader].

edit2: so it seems that log4j uses the thread context class loader. Therefore, one possibility is to disable it. At least, the class loading-related exceptions disappear when using it. But the question remains, if this is a "good" solution...

Also, according to the documentation of Jboss modules with regards to class loading, the TCCL should not be used by frameworks.

Community
  • 1
  • 1
user140547
  • 7,750
  • 3
  • 28
  • 80
  • Is the 3rd party library using the `PropertyConfigurator.configure(Properties)`? – James R. Perkins Mar 08 '16 at 16:58
  • @JamesR.Perkins: yes, the library is calling that – user140547 Mar 08 '16 at 17:02
  • I'm not sure what can be done. slf4j should work even if log4j is being configured. It should just use the logging subsystem configuration. Are you missing log statements in the `server.log`? – James R. Perkins Mar 08 '16 at 17:39
  • @JamesR.Perkins yes the log statements are missing after the first call to the library. One possibility which worked is to put it into a module and use abcustom log4j.jar, I.e. Not a dependency to wildfly's log4j. Then I can use the library's config mechanism which is isolated which cannot be configured using wildfly. Not ideal, but it works – user140547 Mar 08 '16 at 18:17
  • Are you including the slf4j to log4j binding? I would think the slf4j-jboss-logmanager binding should be getting used. – James R. Perkins Mar 09 '16 at 00:38
  • @JamesR.Perkins: There is not slf4j to log4j binding. But now I think the problem is that the library requires a log4j.properties, which is also detected by Wildfly and causes it to use log4j. Then, later the library changes the log4j config. – user140547 Mar 09 '16 at 09:25
  • Ah yes that could be. You can turn of the scanning for the configuration by changing the `use-deployment-logging-config` attribute to false. `/subsystem=logging:write-attribute(name=use-deployment-logging-config, value=false)` – James R. Perkins Mar 09 '16 at 16:04

0 Answers0