Following content is referenced from

http://www.winksaville.com/blog/programming/debug-logging-in-android/

Here are a couple of places that got me started. First the standard java logging mechanism doesn’t work. In addition System.out.print doesn’t work. You need to use the android.util.log.

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;

@StateMachine
public class test extends Activity
{

/** Called with the activity is first created. */
@Override
public void onCreate(Bundle icicle)
{
super.onCreate(icicle);

Log.v(TAG, “onCreate: E”);
setContentView(R.layout.main);
Log.v(TAG, “onCreate: X”);
}

private static final String TAG = “test”;
}
The Log class supports various levels (VERBOSE, DEBUG, INFO, WARN, ERROR, ASSERT) the low-level routine is Log.println(int priority, String tag, String msg). But typically the v, d, i, w, e and a convince routines would be used. So that’s half the game, the other half is to be able to see the output. For that you use “logcat”. In Eclipse if you goto menu “Window/Show View/other/Android/logcat” or if your in the Debug perspective it will be in “Window/Show View/logcat”. Apparently, its not very reliable in Eclipse and executing:

adb logcat

Allows you to see it from a command line, but in Eclipse the log also includes a Date stamp which makes it nice. I was able to get the Eclipse/logcat going by closing than reopening. Of course you mileage may very:) If you look at the links above it appears you can use ddms, but I haven’t used that yet.

Advertisements