2012/2/9 C C <ccb...@yahoo.com>:
> Hello,
>
> I'm seeing a difference in the way Tomcat handles logging exceptions thrown 
> by a servlet, and I wonder if it's a configuration change or if this is 
> simply how Tomcat is expected to behave.
>
> Tomcat versions tested: 5.5.26, 6.0.35, 7.0.25
> OS: Windows 7
> Java: 1.5.0_22 for Tomcat 5.5.26 and 6.0.35, 1.6.0_24 for Tomcat 7.0.25
>
> To test, I created a webapp with a single servlet, ExceptionServlet, that 
> simply throw a ServletException in its service() method, e.g.:
>
> public class ExceptionServlet extends HttpServlet {
>         protected void service(HttpServletRequest arg0, HttpServletResponse 
> arg1)
>
>                         throws ServletException, IOException {
>                 throw new ServletException("HEY SERVLET EXCEPTION");
>         }
> }
>
>
> Further, the webapp uses log4j (1.2.16) and commons-logging (1.1.1). The 
> log4j.properties for the webapp looks like this:
>
> log4j.rootLogger=INFO,A
> log4j.appender.A=org.apache.log4j.RollingFileAppender
>
> log4j.appender.A.file=/opt/personal/logs/ex/ex.info.log
> log4j.appender.A.layout=org.apache.log4j.PatternLayout
> log4j.appender.A.layout.conversionPattern=%m%n
> log4j.appender.A.maxFileSize=10MB
> log4j.appender.A.maxBackupIndex=10
>
>
> 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.
>
> Servlet.service() for servlet ex threw exception
>
> javax.servlet.ServletException: HEY SERVLET EXCEPTION
>         at personal.ExceptionServlet.service(ExceptionServlet.java:17)
>         at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
>         at 
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
> ...
>
>
> However, in a default deployment of Tomcat 6.0.35 or Tomcat 7.0.25, when I 
> drop the webapp in the webapps directory, start up the respective Tomcat, and 
> invoke the ExceptionServlet, the resultant exception message and stack trace 
> appear in the Tomcat's log file, e.g. 
> $TOMCAT_HOME/logs/localhost.2012-02-09.log. It's pretty much the same log 
> message as above:
>
> # from Tomcat 7.0.25
> SEVERE: Servlet.service() for servlet [ex] in context with path [/et] threw 
> exception [HEY SERVLET EXCEPTION] with root cause
> javax.servlet.ServletException: HEY SERVLET EXCEPTION
>         at personal.ExceptionServlet.service(ExceptionServlet.java:17)
>         at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
>         at 
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
> ...
>
>
> I made no configuration changes to any of the Tomcat installations.
>
> So I guess my questions are:
>
> 1. Is it correct to expect that exceptions thrown by a servlet should be 
> logged in the webapp's log files?

No.

Out of the blue I would think that it would be logged into the same
file as if using Servlet.log() call. That goes to Context log file.

Thus it went to the localhost.log file, because you have not
configured a separate one for your context (like e.g. the manager app
does).  I do not know why your configuration worked in 5.5.

Note that logging implementation has changed between 5.5 and 6.0 (as
mentioned in the Migration Guide [1])  in that sense that Tomcat no
longer provides commons-logging.jar library to be used by
applications, but uses its own renamed version of the classes.  Maybe
it is related.

[1] http://tomcat.apache.org/migration.html

> 2. If so, what changed between Tomcat 5.5 and Tomcat 6.0/7.0 that would cause 
> exceptions thrown by a servlet to be logged in Tomcat's log files, or what 
> configuration change do I need to make so that the exception appears in the 
> webapp's logs?
>
> Thanks in advance for any insights into my problem!
>
> Chris
>

Best regards,
Konstantin Kolinko

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to