4 Replies Latest reply on May 26, 2013 12:54 PM by mwigglesworth-redhat

    JBoss 7.1.1.Final - Log4j - EAR File application - Logging not working

    sanssan

      Friends,

      I found few details about the log4j configuration.

       

      We do have few application already running on JBoss 3.x and I am migrating them to JBoss 7.1.1.Final.

       

      Few of the WAR file, JAR files and EAR files. I found some documents to configure the Log4j within JBoss.

       

      It worked great with WAR files.  Still, I couldn't make it work on EAR files.

       

      MyApp.ear
          |
          |- META-INF
              |
              |- application.xml
              |- jboss-deployment-structure.xml
          |
          |- lib
              |
              |- *.jar
          |
          |- MyApp1.war
              |- lib
                  |
                  |- *.jar
              |- WEB-INF
                  |
                  |- server-config.wsdd
                  |- web.xml
                  |- classes
          |
          |- MyApp2.war
              |- WEB-INF
                  |
                  |- ApplicationResources.properties
                  |- web.xml
                  |- classes
          |
          |- MyApp.jar
              |
              |- META-INF
                  |- jboss-service.xml
                  |- jboss.xml
              |- com
      
      

       

      I can't use JBoss logging because it is a big application and all classes using Log4j. Now, what is the best place for log4j.properties?

       

      I can have all EAR classes Logging to 1 configuration....

       

      log4j.appender.file=org.apache.log4j.DailyRollingFileAppender
      log4j.appender.file.DatePattern='.'yyyy-MM-dd
      log4j.appender.file.File=./../standalone/log/MyApp.log
      log4j.appender.file.MaxFileSize=2000KB
      log4j.appender.file.MaxBackupIndex=60
      log4j.appender.file.layout=org.apache.log4j.PatternLayout
      log4j.appender.file.layout.ConversionPattern=%d{dd.MM.yyyy HH:mm:ss.SSS} [%-5p] - %C{1} - %m%n
      log4j.appender.file.Append=false
      
      log4j.rootCategory=DEBUG, file
      
        • 1. Re: JBoss 7.1.1.Final - Log4j - EAR File application - Logging not working
          sanssan

          Hi,

           

          I have fixed this in 2 ways...

           

          Case #1:

           

          log4j.xml

           

          <?xml version="1.0" encoding="UTF-8"?>
          
          <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
          <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
              <appender name="LDAP" class="org.apache.log4j.DailyRollingFileAppender">
                  <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
                  <param name="Append" value="true"/>
                  <param name="File" value="${jboss.server.log.dir}/ldap.log"/>
                  <layout class="org.apache.log4j.PatternLayout">
                      <param name="ConversionPattern" value="%d{dd.MM.yyyy HH:mm:ss.SSS} [%C{1}] - %m%n"/>
                  </layout>
              </appender>
              <category name="com.xyz" additivity="false">
                  <priority value="DEBUG"/>
                  <appender-ref ref="LDAP"/>
              </category>
          </log4j:configuration>
          

           

          Add this a blank jar file and included inside EAR/lib. It worked like good.

           

          Case #2:

           

          Create a module in JBoss as modules and include the module in you application...

           

          com
          |------- xyz
                    |------- log4j
                              |------- myapp
                                        |------- main
                                                  |------- module.xml
                                                  |------- log4j.xml
          

                        

          module.xml

          <?xml version="1.0" encoding="UTF-8"?>
          <module xmlns="urn:jboss:module:1.1" name="com.xyz.log4j.myapp">
              <resources>
                  <resource-root path=""/>
              </resources>
              <dependencies>
                  <module name="org.apache.log4j"/>
              </dependencies>
          </module>
          

           

          And in your EAR/WAR, include your log4j custom module dependency... like below....

           

          <jboss-deployment-structure>
              <deployment>
                  <dependencies>
                      <module name="com.xyz.log4j.myapp" />
                  </dependencies>
                  <!-- Exclusions allow you to prevent the server from automatically adding some dependencies -->
                  <exclusions>
                      <module name="org.apache.log4j"/>
                      <module name="org.slf4j" />
                      <module name="org.apache.commons.logging"/>
                      <module name="org.log4j"/>  
                      <module name="org.jboss.logging"/>
                  </exclusions>
              </deployment>
              <sub-deployment name="myapp.jar">
                  <dependencies>
                      <module name="com.xyz.log4j.myapp" />
                  </dependencies>
                  <exclusions>
                      <module name="org.apache.log4j"/>
                      <module name="org.slf4j" />
                      <module name="org.apache.commons.logging"/>
                      <module name="org.log4j"/>  
                      <module name="org.jboss.logging"/>
                  </exclusions>
              </sub-deployment>
              <sub-deployment name="myapp.war">
                  <dependencies>
                      <module name="com.xyz.log4j.myapp" />
                  </dependencies>
                  <exclusions>
                      <module name="org.apache.log4j"/>
                      <module name="org.slf4j" />
                      <module name="org.apache.commons.logging"/>
                      <module name="org.log4j"/>  
                      <module name="org.jboss.logging"/>
                  </exclusions>
              </sub-deployment>
              <sub-deployment name="myappPortal.war">
                  <dependencies>
                      <module name="com.xyz.log4j.myapp" />
                  </dependencies>
                  <exclusions>
                      <module name="org.apache.log4j"/>
                      <module name="org.slf4j" />
                      <module name="org.apache.commons.logging"/>
                      <module name="org.log4j"/>  
                      <module name="org.jboss.logging"/>
                  </exclusions>
              </sub-deployment>  
          </jboss-deployment-structure>
          
          

          Both worked excellent and In case 2, you can change logging level without touching application deployment.

           

          If you want separate log files for each jar and war, still you create one more logging module and add dependency on the deployment structure xml.

           

          Good luck buddies...

          • 2. Re: JBoss 7.1.1.Final - Log4j - EAR File application - Logging not working
            piyush.mnnit

            For case2, can we moddify logging settings at runtime?

            • 3. Re: JBoss 7.1.1.Final - Log4j - EAR File application - Logging not working
              sanssan

              Jain,

               

              Sorry for the late reply.

               

              You may not need to restart JBoss. But, you may need to redeploy the application.

               

              I hope, this helps.

              • 4. Re: JBoss 7.1.1.Final - Log4j - EAR File application - Logging not working
                mwigglesworth-redhat

                Greetings all.

                 

                I have been trying to figure out why this setup may not work, such that I am in a situation where this setup does not work in case 2.

                 

                The dependency in the module is not pulling in the org.apche.log4j at all, and we end up having to insert log4j.jar into the local classpath for this setup to work.

                 

                Can you provide some further input?

                 

                Simply put, your setup does not work in case 2 for me,unless I insert log4j.jar into the local classpath, under 7.1.3.

                 

                This is referenced on an old 2004 "JBoss Process Build" document, however, nothing really says you should have to put the jar into the local classpath for this setup to work. (At least that I have seen, or been able to locate online.)

                 

                Everyone just says, "include xyz.xml in your module, and put xyz module into your jboss-deployment-structure.xml and it just works," however the setup does not work unless you put the jar into the local classpath, which seems counter intutative to how a module should work. (New to module setup for this type of thing, also.)