Josh is right. Stack tracing is very expensive and should be avoided. It's a little hard to understand what you are doing, but it sounds pretty bad. My first suggestion is to take another look at your production environment and see which logging services already exist and how you can use them.
If you cannot, I would look into already available APIs such as Log4j, SLF4j and Commons to find out how you can use them. Finally, if you are still not using, you can at least look at their source to see how they do it. Also, the source for JUnit analyzes the stack trace, if I remember correctly, so there is another source of ideas.
But my last word will be to make things as simple as possible. Do not go around creating stack traces. Generally speaking, you really only care about them when an exception occurs, and then it is passed to you. You do not need to do anything but pass it on.
drekka
source share