Logging stack trace of Imagej plugin to log file

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Logging stack trace of Imagej plugin to log file

sharanbabuk
Hello,

I'm working on a plugin for imagej, which is a swing application. I see that imagej provides logging feature using log window while application is in action. But, when my application fails for some code, then I don't see any stack trace in log window. Only a small error pops up without entire trace. Do we have any feature/function in imagej which will enable logging stack trace/error lines to be log file (or similar files where we can check entire log of the app), but not in Log window.
This is important because all errors are not popped in the log window and I feel it'll be crazy to debug plugin without logging feature(similar to log4j) and only relying on log window.
Reply | Threaded
Open this post in threaded view
|

Re: Logging stack trace of Imagej plugin to log file

dscho
Hi sharanbabuk,

On Wed, 8 Jan 2014, sharanbabuk wrote:

> I see that imagej provides logging feature using log window while
> application is in action. But, when my application fails for some code,
> then I don't see any stack trace in log window. Only a small error pops
> up without entire trace.

You have to use IJ.handleException(e); to show that log window.

> Do we have any feature/function in imagej which will enable logging stack
> trace/error lines to be log file (or similar files where we can check entire
> log of the app), but not in Log window.

You have to implement that yourself: create a new FileOutputStream, then
pass that to the constructor of a PrintStream, and then use the
Exception#printStackTrac(PrintStream) method:

http://docs.oracle.com/javase/7/docs/api/java/lang/Throwable.html#printStackTrace%28java.io.PrintStream%29

> This is important because all errors are not popped in the log window
> and I feel it'll be crazy to debug plugin without logging
> feature(similar to log4j) and only relying on log window.

You also want to make sure that the part of your plugin's documentation
people actually read contains a big notice that they need to provide you
with the stack trace (i.e. log file) when they report bugs. It is often
forgotten that reporting bugs without providing enough information to make
heads or tails of the problem makes it hard to help.

Ciao,
Johannes

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html