Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I stop stacktraces truncating in logs

Lots of times in Java logs I'll get something like:

Caused by: java.sql.BatchUpdateException: failed batch     at org.hsqldb.jdbc.jdbcStatement.executeBatch(jdbcStatement.java:1102)     at org.hsqldb.jdbc.jdbcPreparedStatement.executeBatch(jdbcPreparedStatement.java:514)     at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)     at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:242)     ... 113 more 

Does anyone know how to get the full stacktrace showing (i.e. show the other 113 lines)?


The JavaDocs (for Java 7) for Throwable have a pretty detailed explanation of what's going on.

like image 782
SCdF Avatar asked Jan 13 '09 02:01

SCdF


2 Answers

When you see '...113 more', that means that the remaining lines of the 'caused by' exception are identical to the remaining lines from that point on of the parent exception.

For example, you'll have

com.something.XyzException   at ...   at ...   at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:242)   at ... <the other 113 lines are here>... Caused by: <the above>. 

The two stack traces 'meet' at AbstractBatcher.executeBatch, line 242, and then from then on the upward call trace is the same as the wrapping exception.

like image 129
Cowan Avatar answered Sep 24 '22 06:09

Cowan


Apache's Commons Lang provides a nice util method ExceptionUtils.printRootCauseStackTrace() which prints a nested stacktrace 'upside down'. The result is much more intuitive.

If you see the result next to the original out of the printStackTrace() method, it will be clear where the '113 more' lines went.

like image 29
Hes Siemelink Avatar answered Sep 24 '22 06:09

Hes Siemelink