When building your awesome Android app, you'll often use the logcat output to debug stuff. Example:
log.d(Constants.REMOVE, "Last updated date is " + lastUpdated.toString());
So, here's the cheesy-simple tip. Sometimes you want to get the context of exactly how you got to the method in question when logging something like this. In the case above, this is in the midst of deserializing some JSON and we could get to this code down a variety of paths. So to get a stacktrace in your log output, just use the other form of the Log call (such as you might normally do within a catch block) with a freshly-minted Exception that you don't throw:
log.d(Constants.REMOVE, "Last updated date is " + lastUpdated.toString(), new Exception());
And voilĂ ! (by the way, I use the Constants.REMOVE tag for transient debug logging, so that I can do an easy sweep of my code to remove them before checkins)
No comments:
Post a Comment