Java / Android - How to print out a full stack trace? Java / Android - How to print out a full stack trace? java java

Java / Android - How to print out a full stack trace?


The following should do the trick:

Log.d("myapp", Log.getStackTraceString(new Exception()));

Note that ...x more at the end does not cut off any information from the stack trace:

(This indicates) 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).

...or in other words, replace x more with the last x lines from the first exception.


There's overrides of all the log methods with (String tag, String msg, Throwable tr) signatures.

Passing an exception as the third parameter should give you the full stacktrace in logcat.


Use Log.getStackTraceString(Throwable t). You can get longer stack traces by digging deeper. For example:

try {    ...} catch(Exception e) {    Log.d("Some tag", Log.getStackTraceString(e.getCause().getCause()));}

Retreived from http://developer.android.com/reference/android/util/Log.html#getStackTraceString%28java.lang.Throwable%29