5 Replies Latest reply on Oct 31, 2012 11:00 AM by James Perkins

    Logging configuration in JBoss AS 7.0.1

    Dipak Jha Newbie

      Hello,

       

      I'm developing a web application that uses log4j for logging and which gets deployed to JBoss 7.0.1 AS as a standalone. I've noticed that the logging configuration subsystem in standalone.xml has no effect, whatsoever, on the log messages that my web application tries to output. I can only exercise control over the logging behaviour of my application by having a separate log4j.xml file in its classpath (more specifically, under WEB-INF/classes).

       

      My question is, is there a way to have one common logging configuration for a web application contained by JBoss 7 and which I can use to control the logging behaviour of BOTH core server components and my own application? I don't mind putting it all together in standalone.xml if I could somehow make JBoss honour the configuration I put in place for my own classes. 

       

      Currently, I have something like the following in standalone.xml. JBoss honours the settings "org.jboss" but completely ignores anything that I configure for "com.mycompany.myexample" below

       

      <subsystem xmlns="urn:jboss:domain:logging:1.1">

                  <console-handler name="CONSOLE" autoflush="true">

                      <level name="ALL"/>

                      <formatter>

                          <pattern-formatter pattern="%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/>

                      </formatter>

                  </console-handler>

                  <periodic-rotating-file-handler name="FILE" autoflush="true">

                      <level name="OFF"/>

                      <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="org.jboss">

                      <level name="DEBUG"/>

                      <handlers>

                          <handler name="CONSOLE"/>

                          <handler name="FILE"/>

                      </handlers>

                  </logger>

       

               <logger category="com.mycompany.myexample">

                      <level name="TRACE"/>

                      <handlers>

                          <handler name="CONSOLE"/>

                          <handler name="FILE"/>

                      </handlers>

                  </logger>

       

       

      Appreciate any help on this. Thanks in advance.

       

       

      Regards

       

      Dipak Jha

        • 1. Re: Logging configuration in JBoss AS 7.0.1
          erasmo2 marciano2 Master

          Hi

           

          you can create this file jboss-web.xml into your web-app

           

           

           

          <jboss-web>

              <valve>

                  <class-name>org.apache.catalina.valves.RemoteIpValve</class-name>

                  <param>

                      <param-name>protocolHeader</param-name>

                      <param-value>x-forwarded-proto</param-value>

                  </param>

              </valve>

              <valve>

                  <class-name>org.apache.catalina.valves.AccessLogValve</class-name>

                  <param>

                      <param-name>prefix</param-name>

                      <param-value>http_access_log.</param-value>

                  </param>

                  <param>

                      <param-name>suffix</param-name>

                      <param-value>.log</param-value>

                  </param>

                  <param>

                      <param-name>pattern</param-name>

                      <param-value>%h %l %u %t %r %s %b %{User-Agent}i %{JSESSIONID}c</param-value>

                  </param>

                  <param>

                      <param-name>directory</param-name>

                      <param-value>host</param-value>

                  </param>

                  <param>

                      <param-name>resolveHosts</param-name>

                      <param-value>false</param-value>

                  </param>

              </valve>

          </jboss-web>

          • 2. Re: Logging configuration in JBoss AS 7.0.1
            Dipak Jha Newbie

            Hi erasmo2 marciano2,

             

            Thank you for your response but unfortunately, this has not resolved my problem. I still cannot control the logging level of my application unless I have a dedicated log4j.xml under WEB-INF/classes.

             

            Interestingly, this problem has been resolved in 7.1.1. I felt happy upgrading to 7.1.1 but my happiness was short-lived since very soon I discovered that on 7.1.1 you cannot hot-deploy modified JSPs without having to redeploy the whole WAR. With 7.0.1 this was possible and I had been able to achieve hot-deployment of JSPs with the following configuration in standalone.xml

             

                <subsystem xmlns="urn:jboss:domain:web:1.0" default-virtual-server="default-host">

                       <configuration>

                            <jsp-configuration development="true"/>

                        </configuration>

             

            Having read through another thread on this forum, I understand this is a known defect in 7.1.1 and which is supposed to have been resolved in 7.1.2. Since 7.1.2 has not yet been officially released, I downloaded its source code from the Git hub and built it myself. The logging and hot-deployment issues mentioned above seemed to have been resolved on 7.1.2 but again my happiness was short-lived. I soon discovered that 7.1.2 redeploys the whole WAR as soon as the server detects any change in any resource (and that includes JSPs). This means you have your server going crazy in the background while you are in development mode and are constantly making changes to and saving your application resources like JSPs. I had the following configuration in place on 7.1.2 for my deployment scanner

             

            <deployment-scanner path="deployments" relative-to="jboss.server.base.dir" scan-enabled="true" scan-interval="5000" auto-deploy-zipped="false" auto-deploy-exploded="true"/>

             

            If I set auto-deploy-exploded="false", the WAR has to be manually deployed every time the server is bounced. FYI, my WAR is always deployed in exploded mode.

             

            I am now left with no option but to revert to good old 7.0.1 and to live with the logging problem (i.e with the need to maintain separate logging configurations for JBoss and my application that it contains) until all the above issues are resolved in a later release, hopefully 7.1.2 final.

             

            Any thoughts from the lead developers of JBoss 7 would be most appreciated.

             

             

            Regards,

             

            Dipak Jha

            • 3. Re: Logging configuration in JBoss AS 7.0.1
              James Perkins Master

              It should work using the configuration in standalone.xml. Make sure you're not including the log4j library in your deployment. That could be the issue.

               

              --

              James R. Perkins

              • 4. Re: Logging configuration in JBoss AS 7.0.1
                Dipak Jha Newbie

                Finally found a solution to my problem. It turns out that you need to explicitly tell the JBoss container that your web application needs log4j. And you do this by adding the following line into /META-INF/MANIFEST.MF

                 

                Dependencies: org.apache.log4j

                 

                A simple, one-liner solution but I've ended up scratching my head for days !! To be honest, I found this solution in one of the threads on this forum

                 

                Anyway, thanks for all your replies.

                 

                 

                Regards

                 

                Dipak Jha

                • 5. Re: Logging configuration in JBoss AS 7.0.1
                  James Perkins Master

                  Correct, I forgot about that. In 7.1.0 it's the dependency is added by default, but not in the older versions.

                   

                  --

                  James R. Perkins