5 Replies Latest reply on May 9, 2008 6:15 AM by jaikiran pai

    Web application logging

    Dan Ciarniello Newbie

      I am porting a web application from a Tomcat 4.1.18/JBoss 3.0.7 combination into JBoss 4.2.2. The application works fine but I would like to send the log output to a file other than server.log. With Tomcat 4.1.18, I was able to specify a log file by adding a "Logger" element to the application's context file in the webapps directory.

      <Context ...>
       <Logger className="org.apache.catalina.logger.FileLogger"
       prefix="myapp." suffix=".txt"
       timestamp="true"/>
      </Context>
      

      How can I accomplish the same thing with JBoss 4.2.2?

      Thanks,
      Dan.


        • 2. Re: Web application logging
          Dan Ciarniello Newbie

          Thanks but that doesn't look like it's what I want.

          My application uses ServletContext.log() to write log messages which I don't want to change. What I would prefer is to be able to drop something in the application's WEB-INF or META-INF directory that does the equivalent of the Logger element and that does not require me to change my code.

          Thanks,
          Dan.

          • 3. Re: Web application logging
            jaikiran pai Master

            Sorry, i haven't used the ServletContext.log API. And right now i dont have my local setup where i can try this. The javadoc mentions this

            Writes the specified message to a servlet log file, usually an event log. The name and type of the servlet log file is specific to the servlet container.


            Can you post a few lines of these logs from the server.log file? That might give someone here a hint as to where/how the configuration needs to be done.


            • 4. Re: Web application logging
              Dan Ciarniello Newbie

              Here's a sample log entry:

              2008-05-01 09:18:28,772 INFO \
              [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/ws/v06]] log entry

              The /ws/v06 is the context-root defined in the ear application.xml

              • 5. Re: Web application logging
                jaikiran pai Master

                In the simplest form you can edit the jboss-log4j.xml and add the following:

                <appender name="MYSERVLET_LOG" class="org.jboss.logging.appender.RollingFileAppender">
                 <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
                 <param name="File" value="${jboss.server.log.dir}/myservlet.log"/>
                 <param name="Append" value="false"/>
                 <param name="MaxFileSize" value="500KB"/>
                 <param name="MaxBackupIndex" value="1"/>
                
                 <layout class="org.apache.log4j.PatternLayout">
                 <param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>
                 </layout>
                 </appender>
                
                <category name="org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/ws/v06]">
                 <priority value="DEBUG"/>
                 <appender-ref ref="MYSERVLET_LOG"/>
                
                 </category>
                


                If the context of the web app changes, then you will have to appropriately change the jboss-log4j.xml category too.