Hi Christopher,
----- Original Message ----- > From: Christopher Schultz <ch...@christopherschultz.net> > To: Tomcat Users List <users@tomcat.apache.org> > Cc: > Sent: Thursday, February 9, 2012 1:00 PM > Subject: Re: ServletException logging changes between 5.5 and 6.0/7.0? > > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Chris, > > On 2/9/12 2:40 PM, C C wrote: >> To test, I created a webapp with a single servlet, >> ExceptionServlet, that simply throw a ServletException in its >> service() method, e.g.: >> ... snip ... > So log4j.properties is located in WEB-INF/classes? > Where is log4j.jar? > My log4j.properties is in WEB-INF/classes, and log4j.jar is in WEB-INF/lib. > Do you have any other code in this example webapp -- for instance, > something that actually loads the log4j.properties file? > I don't have any other code in my example webapp. The only code is that ExceptionServlet. In the ExceptionServlet I don't have any code that loads log4j.properties or configures log4j in any way. > In order to use log4j with Tomcat 6.0 and 7.0, you need to download > some Tomcat "extras" as described here: > http://tomcat.apache.org/tomcat-7.0-doc/logging.html#Using_Log4j > Thanks, I've done this, and found it doesn't really address my problem. My problem is not that I want Tomcat6/7 to use log4j for logging, my problem is that, when my ExceptionServlet throws the ServletException, on TC5.5 the exception was logged in the webapp's log, whereas on TC6/7 it was logged in Tomcat's localhost.log. Konstantin provided a response which seemed to make sense: an exception thrown by a servlet is probably logged using Servlet.log(), so the log message should end up in the Context file. Because my webapp also had commons-logging.jar in WEB-INF/lib, that was probably interfering with / taking over the commons-logging.jar that is shipped with TC5.5. If I remove all the logging jars from my webapp on TC5.5, the behavior looks like TC6/7, where the servlet's exception is logged in Tomcat's log. > So if you haven't done that, then log4j will not be used at all, > unless you have both written some code to initialize log4j during > webapp startup and written an error handler to capture errors and log > them to some kind of log. > >> In a default deployment of Tomcat 5.5.26, I drop the webapp in the >> webapps directory, start up Tomcat, and call the ExceptionServlet. >> The resultant exception message and stack trace appear in the log >> file specified by the webapp's log4j.properties file, as I would >> expect. > > I wouldn't expect that at all, unless your log4j.properties file lives > at the server level and not at the webapp level. So, which is it? > Again, log4j.jar and log4j.properties at the webapp level. I think my understanding of where a servlet exception should be logged is incorrect, and the fact my webapp had commons-logging.jar somehow interfered with where the exception was logged. Does that sound about right? Thanks, Chris --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org