3 Replies Latest reply on Aug 19, 2014 11:26 AM by James Perkins

    What is RIGHT way to load Log4j so that application code uses it and not Jboss logging

    Steve Cohen Newbie

      I am trying to port a system from WebLogic to JBoss EAP v.6.2.


      This system is composed of a large number of related small applications (some WARs, some EARs).  The basic requirement is to minimize the changes required.  One of the fundamental aspects of the system that we are reluctant to change is that all log4j calls are wrapped in a few classes in one jar, which is the only place that dependencies on org.apache.log4j exist.  In Web Logic this jar is included on the classpath when the server starts.


      This does not work with JBoss.  I am trying to port first one simple application, a web app.  For this deployment, the jboss-deployment-structure.xml adds a dependency on com.whatever.log4j.  Then I have defined a module for this jar that has a dependency on org.apache.log4j.  My module is loaded by JBoss without incident, but then when I invoke anything on the web app there is an exception preventing load at the line where a call to getLogger() gets made.  This is delegated within the log4j wrapper jar to a call to log4j's getLogger(), and then JBoss shuts the application down.


      I have tried many things, adding a module in the system tree (modules/system/layers/base), as a module of my own (modules/com/whatever ...) and in call cases the application dies because it is unable to find system:main.


      One thing I have not tried and don't want to try is JBoss's recommended solution of putting log4j.jar in the war file for the web app.  That may be good advice for a single war deployment, but we don't want to do it when the server will be running hundreds of applications.


      To put it bluntly, we want to DEFEAT JBoss's recommendation that all logging go through its logging framework and replace that with an implementation in which all application logs are handled directly with log4j.  It's ok if JBoss itself uses its own framework. But I can't figure out what the module structure needs to look like for this.


      I don't want to keep "trying this and trying that".  Is there detailed documentation explaining all the ins and outs of module descriptors and jboss deployment structure descriptors?  I want to understand it.  But the JBoss docs don't go into that level of detail.


      Message was edited by: Steve Cohen

        • 1. Re: What is RIGHT way to load Log4j so that application code uses it and not Jboss logging
          jaikiran pai Master

          You could just disable/exclude the JBoss Logging subsystem for your deployment, which effectively means that the JBoss logging dependencies implicitly added to your deployment will also be skipped since those deployment processors will not run for your deployment. Here's the documentation https://access.redhat.com/documentation/en-US/JBoss_Enterprise_Application_Platform/6/html/Development_Guide/Exclude_a_Subsystem_from_a_Deployment.html


          In your case I think it should be just a matter of adding:



            <subsystem name="logging" />


          1 of 1 people found this helpful
          • 2. Re: What is RIGHT way to load Log4j so that application code uses it and not Jboss logging
            Steve Cohen Newbie

            This looks like an approach.  I haven't tried it yet because I found the real culprit which was this:  I had used tattletale which told me that my jar had a dependency on <system>.  I copied this right into my module.xml, which is what caused the unresolvable dependency on system:main to appear.


            And at any rate, my problem was in how I described the modules I did want to use, not in how I excluded the modules I didn't want to use.  Does excluding the logging subsystem mean that you don't need to add the definition "-Dorg.jboss.as.logging.per-deployment=false" to the server configuration?


            But I'm not through yet.  This may yet prove something I'll want to use, especially, if I could do so on a global (server-wide) level.  Is this possible?


            Also, is there a list of subsystems that can be excluded in this way?  That might be useful.

            • 3. Re: What is RIGHT way to load Log4j so that application code uses it and not Jboss logging
              James Perkins Master

              Excluding the logging subsystem won't work for EAP 6.2, but will for EAP 6.3. In EAP 6.2 and below the logging dependencies were not added via the logging subsystem but as explicit dependencies from the server. You'll need to use an approach of excluding the log4j dependency and including your log4j dependency.


              The -Dorg.jboss.as.logging.per-deployment system property is only used to enable/disable a logging processor from looking for a logging configuration file. If you don't include any of logging configuration files, e.g. log4j.properties or log4j.xml in this case, then you don't need to worry about that property.


              The server however does explicitly add a log4j dependency. It would be helpful to see the exception as maybe you just need to add a dependency of org.apache.log4j on your com.whatever.log4j module.


              You can exclude any subsystem from your deployments. Which may or may not break your deployments . As far as I know there is know dependency graph on what subsystems rely on other subsystems. There is however some information on explicit dependencies.



              James R. Perkins