File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Where's printstackTrace() output ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Where Watch "Where New topic

Where's printstackTrace() output ?

Graeme Byers
Ranch Hand

Joined: Apr 16, 2004
Posts: 127
When my Model catches an exception then re-throws it to the Controller which calls printStackTrace() , the Apache-Tomcat logs do not record where the Model had the problem . Can AT be configured to write printStackTrace() to the logs?
I know that I can put printStackTrace (PrintStream) into a String and log() that String (the String has all that I require) , but do I need to do this ?
Thank you.
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13037
It might be simpler to use the ServletContext log( msg, throwable ) method.

Pete Nelson
Ranch Hand

Joined: Aug 30, 2010
Posts: 147

Apache Tomcat typically writes anything from STDOUT to logs/catalina.out .

My personal preference for logging is Apache log4j - . Logging is all controlled by a properties file, allowing you to easily change logging levels and appenders (log files) without touching your java code. Each logging method can take a message and/or an optional Exception, which will give you similar output to calling Exception.printStackTrace().

In preparing for battle I have always found that plans are useless, but planning is indispensable. -- Dwight D. Eisenhower
Graeme Byers
Ranch Hand

Joined: Apr 16, 2004
Posts: 127
Peter : I think Log4J is really for continuous monitoring and logging of events.
Bill's solution gives the same results and is simpler than the one I mentioned.
Thank you both.
I agree. Here's the link:
subject: Where's printstackTrace() output ?
It's not a secret anymore!