Win a copy of Microservices Testing (Live Project) this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Piping the stack traces to a file

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using tomcat 5.5 on windows xp. I don't know why but it doesn't write the stack traces to the log file. So I am looking for alternative ways. Is there any way to pipe the stack traces to a file without altering the source code?

Thanks... Best regards

Mert Nuhoglu
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The reason being that exception messages are written to the standard error stream rather than standard out. Use the & character on the command line to redirect standard error.
You should also look into using Tomcat's integral logging (with the Jakarta Commons classes). Using a logging API gives you a lot of functionality compared to plain System.out
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also note that printStackTrace() has an optional stream argument. You can make it write traces anywhere you like by providing an output stream. My homemade logger lets me do this:

The stream is really a byte array output stream so I can capture the contents and write them to all the log listeners. You could make a file output stream I suppose.
 
Mert Nuhoglu
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, thanks for your replies.

Joe, I tried to redirect the output using the characters > and &.

I went to the tomcatHome/bin directory and gave the following command:

startup.bat & out.txt

But only the environment variables are written to the out.txt file. The stack traces are not written...

When running startup.bat, the application produces another frame of command line. And the stack traces are written to that screen. The last command in the batch file is:

start "Tomcat" "C:\Program Files\Java\jdk1.5.0_01\bin\java" -Djava.endorsed.dirs="C:\tomcat\common\endorsed" -classpath "C:\Program Files\Java\jdk1.5.0_01\lib\tools.jar;C:\tomcat\bin\bootstrap.jar" -Dcatalina.base="C:\tomcat" -Dcatalina.home="C:\tomcat" -Djava.io.tmpdir="C:\tomcat\temp" org.apache.catalina.startup.Bootstrap start

Thus I thought I should put & character to the end of this command. But it didn't help me neither...

Could you help me a little more?

Thanks...
 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Mert Nuhoglu:

start "Tomcat" "C:\Program Files\Java\jdk1.5.0_01\bin\java" -Djava.endorsed.dirs="C:\tomcat\common\endorsed" -classpath "C:\Program Files\Java\jdk1.5.0_01\lib\tools.jar;C:\tomcat\bin\bootstrap.jar" -Dcatalina.base="C:\tomcat" -Dcatalina.home="C:\tomcat" -Djava.io.tmpdir="C:\tomcat\temp" org.apache.catalina.startup.Bootstrap start



The command "start" opens a new command window. The second argument, "Tomcat" is the title for that new command window. The important commands, the ones you want to issue, are the third and following commands.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic