Sunday, December 19, 2010

Console traces for debugging applications

One of the first things we usually need when we are developing an application is to insert log traces. In Android Stack System.out.println standard function doesn't works. If we need to see traces on Android console we must use the android.util.Log package.

We have different methods depending on the trace level we use:
  • VERBOSE: Log.v()
  • DEBUG: Log.d()
  • INFO: Log.i()
  • WARN: Log.w() 
  • ERROR: Log.e()

We can use a TAG for each class, for each activity or for the whole system in order to group the traces:

private static final String TAG = "MyClass";

So, debug methods can be used as follows:

Log.d( TAG, "String to be traced");  

We don't need to do any more.

UPDATE: I have found some applications for the smartphones which allow to see, filter by tag or level, save on SD and e-mail all the system traces. Here you have some of them:

No comments:

Post a Comment