Output the log in the program, using the Android.util.Log class.
This class provides a number of static methods
LOG.V (string tag, string msg);
LOG.D (string tag, string msg);
LOG.I (string tag, string msg);
LOG.W (string tag, string msg);
LOG.E (string tag, string msg);
correspond to Verbose, Debug, Info, Warning,error respectively.
Tag is an identity, can be any string, you can usually use the class name + method name, primarily to provide a filter condition when viewing the log.
The program does not output any information in the IDE's console after it has been run.
If you want to view the log later, use the
ADB logcat
For more information on the ADB, please check the official website.
When the ADB logcat is executed, all log information is displayed in real time in a tail manner.
At this point we usually need to filter the information to display the information we need, at which time we specify the tag is useful.
ADB logcat-s myandroid:i
This will display only the tag as myandroid, the level I or the level higher than I (warning,error) log information.
The sample code is as follows:
Java code package com.zijun; import android.app.activity; import android.content.context; import android.graphics.canvas; import android.os.bundle; import android.util.log; import android.view.motionevent; import android.view.view; public class myandroid extends activity { protected static final String Activity_tag= "Myandroid"; @Override protected void oncreate (bundle icicle) { super.oncreate (Icicle); setcontentview (This) (New myview); &nBsp } public class MyView extends view { public myview (Context c) { super (c); } @Override protected void ondraw ( Canvas canvas) { @Override public boolean onmotionevent (motionevent event) {             LOG.I (MyAndroid.ACTIVITY_TAG, "= ===========================");           LOG.D (myandroid.activity_tag, "HAHA  this is a DEBUG of MyAndroid. ");             LOG.I (MyAndroid.ACTIVITY_ tag, "haha , this is a info of myandroid. ");             LOG.W (MyAndroid.ACTIVITY_ tag, "haha , this is a warning of myandroid. "); return True } } &nbsP }
After the program is run, execute ADB logcat-s myandroid:i at the command line
Then click the mouse on the phone simulator screen to see the corresponding log information.
Print line numbers
Throwable state = new Throwable ();
stacktraceelement[] stacktraces = State.getstacktrace ();
for (Stacktraceelement st:stacktraces) {
System.out.println (St.tostring ());
}
Through Stacktraceelement, we can get the current class,filename,linenumber,methodname