3 Replies Latest reply on Aug 12, 2015 6:27 AM by Rajasekhar Palle

    How to configure log4j for JBoss EAP 6.0.1?

    Madhusudhan raju Newbie

      Hi,

       

      We are in process of migrating from JBoss 5.1.2 to JBoss 6.0.1 EAP.

       

      While deploying the EAR file in "JBoss-5.1\server\deploy" directory, we package log4j.jar in the application (war and jar) library and configured logging using jboss-log4j.xml under

      "JBoss-5.1"\server\conf directory. Our package is as follows:

       

                Myear.ear

                   |----myWar.war

                   |----myJar.jar

       

      We are now able to run the application in JBoss-6.0.1 successfully with some modifications according to JBoss 6.0.1 Admin guide, but only issue is around the application logging.

       

      While running the appliaction on JBoss-6.0.1 except DEBUG level log statements, INFO, ERROR, FATAL, WARN logs are getting logged to server.log.

       

      I've packaged log4j.jar under "myWar.war/Web-Content/WEB-INF/lib" directory logging in standalone.xml as below:

       

      <subsystem xmlns="urn:jboss:domain:logging:1.1">
                  <console-handler name="CONSOLE">
                      <level name="INFO"/>
                      <formatter>
                          <pattern-formatter pattern="%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/>
                      </formatter>
                  </console-handler>
                  <periodic-rotating-file-handler name="FILE">
                      <formatter>
                          <pattern-formatter pattern="%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/>
                      </formatter>
                      <file relative-to="jboss.server.log.dir" path="server.log"/>
                      <suffix value=".yyyy-MM-dd"/>
                      <append value="true"/>
                  </periodic-rotating-file-handler>
                  <logger category="com.arjuna">
                      <level name="WARN"/>
                  </logger>
                  <logger category="org.apache.tomcat.util.modeler">
                      <level name="WARN"/>
                  </logger>
                  <logger category="sun.rmi">
                      <level name="WARN"/>
                  </logger>
                  <logger category="jacorb">
                      <level name="WARN"/>
                  </logger>
                  <logger category="jacorb.config">
                      <level name="ERROR"/>
                  </logger>

         <logger category="org.jboss">
               <level name="INFO"/>
            </logger>

          <root-logger>
                      <level name="INFO"/>
                      <handlers>
                          <handler name="CONSOLE"/>
                          <handler name="FILE"/>
                      </handlers>
                  </root-logger>

       

      If am setting the category to "org.jboss" and level to DEBUG, it is logging FINE, FINER and FINEST logs which is increasing the server.log enormosly.

       

      I see a log4j.jar under "JBoss-6.0.1\module\org\apache\log4j\main\"  i removed the log4j.jar under the lib and configured the module.xml file in "JBoss-6.0.1\module\org\apache\log4j\main\" as following

       

      <module xmlns="urn:jboss:module:1.1" name="org.apache.log4j">

          <resources>

              <resource-root path="log4j-1.2.16-redhat-2.jar"/>

          </resources>

          <dependencies>

           <module name="javax.api"/>

           <module name="javax.transaction.api"/>

           <module name="org.dom4j" optional="true"/>

           <module name="org.jboss.logmanager"/>

           <module name="org.jboss.modules"/>

          </dependencies>

      </module>

       

      With above configuration, when JBoss is started i get to see the below erro and server fails to start:

       

      05:20:35,924 ERROR [stderr] (ajp-/127.0.0.1:8009-1) log4j:WARN No appenders could be found for logger (app.com.servlet.MyServlet).

      05:20:35,924 ERROR [stderr] (ajp-/127.0.0.1:8009-1) log4j:WARN Please initialize the log4j system properly.

      05:20:35,925 ERROR [stderr] (ajp-/127.0.0.1:8009-1) log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

      05:59:47,388 INFO  [org.jboss.as.osgi] (MSC service thread 1-1) JBAS011908: Unregister module: Module "deployment.Myear.ear.Mywar.war:main" from Service Module Loader

       

      How can i use this "log4j-1.2.16-redhat-2.jar" provided by JBoss 6.0.1 for my application logging by supressing the FINE, FINER and FINEST logs which are getting generated by sqljdbc.jar whenever application is connecting to database.

       

      Can someone pls help me in logging DEBUG statements to server.log file?

        • 1. Re: How to configure log4j for JBoss EAP 6.0.1?
          James Perkins Master

          In JBoss EAP 6 during deployment of your application the logging subsystem attempts to locate the jboss-log4j.xml file you have in your application. My guess is it's found this and configures the root logger to DEBUG in log4j. If you don't want logging for your deployment to be configured based on your jboss-log4j.xml then pass the org.jboss.as.logging.per-deployment=false property when starting up the server or add it to the system properties.

           

          Why FINER and FINEST are being logged when you set it to debug though I don't know. That seems odd to me. I would first try passing the property I mentioned above and see if that changes anything. Note though at that point all the logging configuration is based on the logging subsystem settings which has the bonus of allowing for runtime changes.

           

          --

          James R. Perkins

          • 2. Re: How to configure log4j for JBoss EAP 6.0.1?
            Madhusudhan raju Newbie

            Atlast got this issue fixed by the following approach:

             

            Step 1: Under the directory “src” in myWeb.war placed the log4.jar file

            Step 2:Under the directory “src” in myWeb.war placed the log4.jar configuration file (log4j.xml)

            Step 3: Created “jboss-deployments-structure.xml” under swstoreWeb\Web Content\META-INF\ directory to exclude the Jboss 6 provided logging framework as below:

             

            <jboss-deployment-structure>

            <deployment>

                <exclusions>

                    <module name="org.apache.log4j" />

                </exclusions>

              </deployment>

            </jboss-deployment-structure>

             

            Step 4:Build the ear/war file and verify the added files are in expected place

             

                 1.      Log4j.jar and log4j.xml should be present in classes folder    

                 2.      Standalone-deployment-structure.xml should be in myWeb.war\Web Content\META-INF\

             

            Step 5: Start the Jboss server and login to management console. Navigate to System properties and add the following value:

             

                                    Name: -Dorg.jboss.as.logging.per-deployment

                                     Value: false

             

            With the above approach, i am now able to overcome the FINE, FINER AND FINEST logs by using my own application logging framework.

             

            Regards,

            Madhu

            • 3. Re: How to configure log4j for JBoss EAP 6.0.1?
              Rajasekhar Palle Newbie

              I too had similar problem, my app is EAR packaged with multiple WAR apps. One of WAR application has log4j.xml file to create custom app log file.

              With above mentioned configurations It worked when deploy individual WAR in JBOSS eap-6.3.3, but if deploy EAR custom log file not created and find no errors in server log, any help here would be greatly appreciated.