aspose file tools*
The moose likes I/O and Streams and the fly likes Piping the stack traces to a file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Piping the stack traces to a file" Watch "Piping the stack traces to a file" New topic
Author

Piping the stack traces to a file

Mert Nuhoglu
Greenhorn

Joined: Apr 22, 2004
Posts: 10
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

Joined: Oct 29, 2001
Posts: 8997
    
    9

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


[How To Ask Questions On JavaRanch]
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
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.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Mert Nuhoglu
Greenhorn

Joined: Apr 22, 2004
Posts: 10
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

Joined: Oct 29, 2001
Posts: 8997
    
    9

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Piping the stack traces to a file