Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
330 views
in Technique[技术] by (71.8m points)

java - Print full call stack on printStackTrace()?

I need to write small a log analyzer application to process some log files generated by a 3rd party closed source library (having custom logger inside) used in my project.

In case of an exception entry in the log I need to collect aggregated information about the methods involved along the stack trace from the top to the actual place of the exception.

Unfortunately, by default Java printStackTrace() does not print every method in the call stack but up to a certain number and the rest is just referenced as 16 more....

If I could catch the exception myself I would use the getStackTrace() and print it myself but the root cause is never included in the exception this library throws.

Is there a way to ask Java to print the entire call stack in the stacktrace?

Apart from my situation do common logging frameworks have option for this?

Edit: The program runs on Sun's JVM with JDK 1.5.0_09. No option to change that.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

here is an explanation of the 'caused by' and '... n more' lines in the printed trace. see also the JavaDoc for printStackTrace. you might not have any work to do.

Note the presence of lines containing the characters "...". These lines indicate that the remainder of the stack trace for this exception matches the indicated number of frames from the bottom of the stack trace of the exception that was caused by this exception (the "enclosing" exception). This shorthand can greatly reduce the length of the output in the common case where a wrapped exception is thrown from same method as the "causative exception" is caught.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...