9 Replies Latest reply on Oct 11, 2012 3:11 PM by fduartej

    How to setting Jboss 7 and log4j config outside of the war or ear

    fduartej

      Hi Everybody:

       

      I have been working with WebLogic and Spring for several years, but now I am working with JBOSS 7 and I have some doubs about what is the reason that Jboss not fine when I tried  to make some setting about log4j in this case all of properties about log4j are outside of the WAR and EAR because the main reason in my job is that config is only changed for operator, that never should not modified the Component deployed on the server, they only can change the setting that is in other folder, but when I have been setting it on Jboss and  all of log is displayed on the server.log but not on the file that I have set.

       

      Please, could you help me, I am sending some of setting that I have done.

       

      I have been trying with that fragment first

      -------------------------------------------------------------

      <bean id="log4jInitialization"

              class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">

              <property name="targetClass" value="org.springframework.util.Log4jConfigurer" />

              <property name="targetMethod" value="initLogging" />

              <property name="arguments">

                  <list>

                      <value>file:///opt/application-logs/axcess-es-platform-auditevent/config/axcess-es-platform-auditevent.properties</value>

                  </list>

              </property>

       

      Then I have changed it for this

      ------------------------------------------

         <context-param>

              <param-name>log4jConfigLocation</param-name>

              <param-value>file:///opt/application-logs/axcess-es-platform-auditevent/config/axcess-es-platform-auditevent.properties</param-value>

          </context-param>

       

          <listener>

              <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>

          </listener>

       

      Some of forums say that it should be added jboss-deployment-structure.xml in both of above setting I have added the setting below on the WEB-INF and META-INF

       

      <jboss-deployment-structure>

          <deployment>

              <exclusions>

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

              </exclusions>

          </deployment>

      </jboss-deployment-structure>

       

      It is my log4j properties (axcess-es-platform-auditevent.properties)

       

      log4j.rootLogger=ALL, logfile

       

      log4j.appender.stdout=org.apache.log4j.ConsoleAppender

      log4j.appender.stdout.layout=org.apache.log4j.PatternLayout

      log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE}|%x|%p|%F:%L|%m%n

       

      log4j.appender.logfile=org.apache.log4j.DailyRollingFileAppender

      log4j.appender.logfile.File=/opt/application-logs/axcess-es-platform-auditevent/axcess-es-platform-auditevent.log

      log4j.appender.logfile.DatePattern='.'yyyy-MM-dd

      log4j.appender.logfile.layout=org.apache.log4j.PatternLayout

      log4j.appender.logfile.layout.ConversionPattern=%d{dd/MM/yyyy HH:mm:ss Z}|%x|%p|%F:%L|%m%n

       

      Please, I hope that you can help me.

       

      Thanks in advance

      Fred

        • 1. Re: How to setting Jboss 7 and log4j config outside of the war or ear
          jamezp

          Do the files you have in the log4j.properties get created? If so it sounds like the jboss-deployment-structure.xml may not be in the correct place. In an EAR it needs to be in the META-INF directory. In a WAR it can be in either the META-INF or WEB-INF.

           

          Also, what version of JBoss AS 7 are you using?

           

          --

          James R. Perkins

          • 2. Re: How to setting Jboss 7 and log4j config outside of the war or ear
            fduartej

            The file is on the correct folder as you can see below, but I have seen some part of the code that is not using log4j else common logging 

             

            axcess-es-platform-auditevent.war

            └───WEB-INF

                │   jboss-deployment-structure.xml

                │   web.xml

             

            And I have added on the code some lines about log4j

             

            package event.web.controller;

             

            import java.util.HashMap;

            import java.util.Map;

             

            import org.apache.commons.logging.Log;

            import org.apache.commons.logging.LogFactory;

            import org.apache.log4j.Logger;

            import org.springframework.beans.factory.annotation.Autowired;

            import org.springframework.beans.factory.annotation.Qualifier;

            import org.springframework.stereotype.Controller;

            import org.springframework.web.bind.annotation.RequestBody;

            import org.springframework.web.bind.annotation.RequestMapping;

            import org.springframework.web.bind.annotation.RequestMethod;

            import org.springframework.web.bind.annotation.ResponseBody;

             

            @Controller

            public class AuditEventController {

             

                private static final Log log = LogFactory.getLog(AuditEventController.class);

                private static Logger log1=Logger.getLogger(AuditEventController.class);

             

                @RequestMapping(value="/auditevent.htm",method=RequestMethod.POST)

                @ResponseBody

                public Map<String,String> registerRESTEvent(@RequestBody AuditEvent event){

                    if(log1.isDebugEnabled()) log1.debug("event1="+event);

                    if(log.isDebugEnabled()) log.debug("event="+event);

                Map<String,String> response = new HashMap<String,String>();

                return reponse;

              }

            }

             

            And It work well, but the common loggin not in this case also I added this setting on the jboss-deployment-structure.xml as you can see below and add also the lib  commons-logging-1.0.4.jar

             

            <?xml version="1.0" encoding="UTF-8"?>

            <jboss-deployment-structure>

               <deployment>

                 <exclusions>

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

                   <module name="org.apache.commons.logging" />

                 </exclusions>

               </deployment>

            </jboss-deployment-structure>

             

            Because all of spring libs are using common loggin but it does not work displaying the log on the file that is setting else on the server.log

             

            The version of Jboss is jboss-as-7.1.1.Final

            • 3. Re: How to setting Jboss 7 and log4j config outside of the war or ear
              jamezp

              I'm not too familiar with Spring, but you might need to exclude a few more logging frameworks. I think Spring also uses slf4j.

               

              Anyway, try this in your jboss-deployment-structure.xml:

               

               

              <?xml version="1.0" encoding="UTF-8"?>
              <jboss-deployment-structure>
                 <deployment>
                   <exclusions>
                     <module name="org.apache.log4j" />
                     <module name="org.apache.commons.logging" />
                     <module name="org.slf4j" />
                     <module name="org.slf4j.jcl-over-slf4j" />
                     <module name="org.jboss.logging.jul-to-slf4j-stub" />
                   </exclusions>
                 </deployment>
              </jboss-deployment-structure>
              
              

               

              I'm not sure all those are needed, but it would exclude them all. You'd also have to include a log4j, slf4j, commons-logging and jul-to-slf4j library in your deployment too.

               

              --

              James R. Perkins

              • 4. Re: How to setting Jboss 7 and log4j config outside of the war or ear
                fduartej

                Thanks James, It work fine only one question more all of hibernate log is displayed on the server.log but not on my own file logger maybe it need an other setting, I dont know why is needed?

                 

                server.log

                --------------

                16:44:34,172 INFO  [stdout] (http--127.0.0.1-8080-1) Hibernate: insert into table

                 

                 

                Thanks in advance

                Fred

                • 5. Re: How to setting Jboss 7 and log4j config outside of the war or ear
                  fduartej

                  I found this...log4j.logger.org.hibernate.SQL=ALL thaks a lot

                  • 6. Re: How to setting Jboss 7 and log4j config outside of the war or ear
                    jamezp

                    No problem, and thanks for letting me know about the Hibernate thing. I was wondering the other day how to do that myself, but hadn't looked into it yet.

                     

                    --

                    James R. Perkins

                    • 7. Re: How to setting Jboss 7 and log4j config outside of the war or ear
                      fduartej

                      I found a litle mistake, I have been triying with the setting that you sent me, but it not work well, I have added some lines that is uncoment, the lines that you sent me are commented

                       

                      <?xml version="1.0" encoding="UTF-8"?>

                      <jboss-deployment-structure>

                         <deployment>

                           <exclusions>

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

                             <module name="org.apache.commons.logging" />

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

                             <module name="org.jboss.logging.jul-to-slf4j-stub"/>

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

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

                             <module name="org.slf4j"/>

                       

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

                             <module name="org.apache.commons.logging" />

                             <module name="org.slf4j" />

                             <module name="org.slf4j.jcl-over-slf4j" />

                             <module name="org.jboss.logging.jul-to-slf4j-stub" /-->

                            

                           </exclusions>

                         </deployment>

                      </jboss-deployment-structure>

                       

                      Because these line not work well and the common loggin yet is not working as you can see below

                       

                      10/10/2012 17:40:03 -0400||DEBUG|AuditEventController.java:54|event1=com.axcessfinancial.component.audit.event.domain.AuditEvent@1bd736bd

                       

                      The tag event1 was created in order to use with log4j but event was created to use common loggin but it is not displayed on the file....why? is a good question...:(

                       

                      Please do you know what setting are missing.....

                       

                      Regards

                      Fred

                      • 8. Re: How to setting Jboss 7 and log4j config outside of the war or ear
                        jamezp

                        I'm not too sure what's missing. The only thing I can think of is maybe commons-logging sees the JBoss Log Manager before it sees the log4j log manager. That's just a guess though. You've got all 4 logging modules that are added at deployment time excluded. The only other module you *might* want to exclude would be org.slf4j.impl, but I wouldn't think it would be needed.

                         

                        --

                        James R. Perkins

                        • 9. Re: How to setting Jboss 7 and log4j config outside of the war or ear
                          fduartej

                          Well, It is the great solution for this problem that I found:

                           

                          Add the jboss-deployment-structure.xml file on the WEB-INF if you use WAR component on META-INF if you use EAR component

                           

                          <?xml version="1.0" encoding="UTF-8"?>

                          <jboss-deployment-structure>

                             <deployment>

                               <exclusions>

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

                                  <module name="org.apache.commons.logging" />

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

                                 <module name="org.jboss.logging.jul-to-slf4j-stub"/>

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

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

                                 <module name="org.slf4j"/>

                               </exclusions>

                             </deployment>

                          </jboss-deployment-structure>

                           

                          If you want to refresh what are the changes when you change the log4j properties you have to use

                           

                            <context-param>

                              <param-name>log4jConfigLocation</param-name>

                              <param-value>file:///log/app/config/applog4j.properties</param-value>

                            </context-param>

                            <context-param>

                              <param-name>log4jRefreshInterval</param-name>

                              <param-value>1000</param-value>

                            </context-param>

                            <listener>

                              <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>

                            </listener>

                           

                          The setting for the applog4j.properties, depends what you use in my case I am using spring 3.1 and hibernate

                           

                          log4j.rootLogger=INFO, logfile

                           

                          # Log everything.

                          log4j.logger.org.hibernate=INFO

                           

                          # Log all JDBC parameters

                          log4j.logger.org.hibernate.type=INFO

                          log4j.logger.org.hibernate.SQL=INFO

                           

                          # log spring

                          log4j.logger.org.springframework=INFO

                           

                          log4j.appender.stdout=org.apache.log4j.ConsoleAppender

                          log4j.appender.stdout.layout=org.apache.log4j.PatternLayout

                          log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE}|%x|%p|%C{-5}:%L|%m%n

                           

                          log4j.appender.logfile=org.apache.log4j.DailyRollingFileAppender

                          log4j.appender.logfile.File=/log/app/app.log

                          log4j.appender.logfile.DatePattern='.'yyyy-MM-dd

                          log4j.appender.logfile.layout=org.apache.log4j.PatternLayout

                          log4j.appender.logfile.layout.ConversionPattern=%d{dd/MM/yyyy HH:mm:ss Z}|%x|%p||%C{-5}:%L|%m%n

                           

                          Add pom dependencies

                           

                          <dependency>

                                      <groupId>log4j</groupId>

                                      <artifactId>log4j</artifactId>

                                      <version>1.2.14</version>

                                  </dependency>

                                  <dependency>

                                      <groupId>org.slf4j</groupId>

                                      <artifactId>jcl-over-slf4j</artifactId>

                                      <version>1.6.1</version>

                                      <scope>runtime</scope>

                                  </dependency>

                                  <dependency>

                                      <groupId>org.slf4j</groupId>

                                      <artifactId>slf4j-api</artifactId>

                                      <version>1.6.1</version>

                                      <scope>runtime</scope>

                                  </dependency>

                                  <dependency>

                                      <groupId>org.slf4j</groupId>

                                      <artifactId>slf4j-log4j12</artifactId>

                                      <version>1.6.1</version>

                                      <scope>runtime</scope>

                                  </dependency>