Hi all,

I am in the process of upgrading from tomcat-3.3 to tomcat-5.5 and would 
greatly appreciate if you could let me know whether I understood tomcat-5.5's 
default logging correctly.

As of tomcat 5.5 Context element does not have a Logger sub-element. Logging 
can be configured with log4j or java.util.logging. I went with  
java.util.logging, which is turned on by default and uses 
<CATALINA_HOME>/conf/logging.properties. To be more exact Tomcat does not use 
java.util.logging as is but rather "will, in the default configuration, replace 
the default LogManager implementation with a container friendly implementation 
called JULI" (extract from http://tomcat.apache.org/tomcat-5.5-doc/logging.html)

The following describes how the default logging (ie java.util.logging) works in 
tomcat-5.5 (well, it describes how I saw it working :) ):

I. 
When using <CATALINA_HOME>/conf/logging.properties from the box (ie without any 
modifications) all the logging performed in the particular web app goes to the 
handlers defined in the .handlers clause, or in other words it gets logged into 
the logs/catalina.<dateStamp>.txt file and the console. In addition, all the 
exceptions thrown by the web app go to the 2localhost handler, ie they are 
logged into the localhost.<dateStamp>.log

That's what <CATALINA_HOME>/conf/logging.properties has:
--------------------------------------------------
handlers = 1catalina.org.apache.juli.FileHandler, ...., 
2localhost.org.apache.juli.FileHandler,...

.handlers = 1catalina.org.apache.juli.FileHandler, 
java.util.logging.ConsoleHandler

....
1catalina.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
1catalina.org.apache.juli.FileHandler.prefix = catalina.
....
2localhost.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
2localhost.org.apache.juli.FileHandler.prefix = localhost.
--------------------------------------------------

that is what our web app has
--------------------------------------------------
public class TestServlet extends HttpServlet {
  public void doGet(H....
  {
        Logger logger1 = Logger.getLogger("test");  
      Handler[] handlers = logger1.getHandlers();
      for (int i = 0; i < handlers.length; i++) {
            Handler handler = handlers[i];
            System.out.println(handler);
      } 
      System.out.println("handlers.size: " + handlers.length);
        
      logger1.info("INFO logging is successful");
        
      throw new IllegalStateException("test exception");
  }
}
--------------------------------------------------

once TestServlet serves HTTP GET request the result is:

a) Console has the following
        handlers.size: 0        // result of System.out.println
        Nov 23, 2005 5:24:37 PM com.SSMB.TestProj.servlets.TestServlet doGet // 
result of logging
          INFO: INFO logging is successful 

b) catalina.2005-11-23.log has the following:
        Nov 23, 2005 5:24:37 PM com.SSMB.TestProj.servlets.TestServlet doGet // 
result of logging
          INFO: INFO logging is successful 

c) localhost.2005-11-23.log has the following
        java.lang.IllegalStateException: test exception                 // 
result of throwing the ISEx
                at 
com.SSMB.TestProj.servlets.TestServlet.doGet(TestServlet.java:45)


II. 
If we want the logging performed by a particular web app and the exceptions 
thrown by it to go to a particular file we can modify 
<CATALINA_HOME>/conf/logging.properties.  Let's assume that we have got a web 
app that runs on the /test context.

That's how <CATALINA_HOME>/conf/logging.properties should be modified
--------------------------------------------------
# add new handler, 6test.org.apache.juli.FileHandler, to the list 
handlers = 
1catalina.org.apache.juli.FileH....,...,6test.org.apache.juli.FileHandler
....
## new line - 'test' logger will only log into 6test handler
test.handlers=6test.org.apache.juli.FileHandler
...
## define 6test file handler - all logging done via 'test' logger 
## will go to test.<dateStamp>.txt file
6test.org.apache.juli.FileHandler.level = FINE
6test.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
6test.org.apache.juli.FileHandler.prefix = test.
....
## all of the exceptions coming from /test context are to be logged into 6test 
handler.
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/test].level = 
INFO
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/test].handlers 
= 6test.org.apache.juli.FileHandler
--------------------------------------------------

once TestServlet (see its doGet method content above) serves HTTP GET request 
the result is:

a) Console has the following
        [EMAIL PROTECTED] // result of System.out.println
        handlers.size: 1                                // result of 
System.out.println

b) test.2005-11-23.log has the following:
        Nov 23, 2005 6:17:21 PM com.SSMB.TestProj.servlets.TestServlet doGet // 
result of logging
        INFO: INFO logging is successful
        Nov 23, 2005 6:17:21 PM org.apache.catalina.core.StandardWrapperValve 
invoke
        SEVERE: Servlet.service() for servlet TestServlet threw exception       
// result of throwing the ISEx
        java.lang.IllegalStateException: test exception
                at 
com.SSMB.TestProj.servlets.TestServlet.doGet(TestServlet.java:45)
                


Thanks a lot for reading my "tomcat5.5 default logging" novel. I'd greatly 
appreciate if you could give me a feedback on whether I described the tomcat5.5 
logging behaviour correctly.


Kind regards,

Alexandre.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to