Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Piping the stack traces to a file

 
Mert Nuhoglu
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • 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
 
Joe Ess
Bartender
Posts: 9320
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • 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
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • 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
  • 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: 9320
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic