When debugging the code we need to look at the debug information, then we need to use the Android log class.
Android.util.Log commonly used methods include the following 5 :log.v () log.d ( ) log.i () LOG.W () and log.e () . According to the first letter corresponds to VERBOSE,debug,info, Warn,error.
1, log.v debugging color is black , any message will be output, here V for verbose wordy meaning, usually use is LOG.V ("," ");
2, LOG.D output color is blue , only the meaning of debug debugging output, but he will output the upper level of information, filtering up can be DDMS by the logcat tag to choose.
3, LOG.I output is green , general informational message information, it will not output LOG.V and LOG.D information, but will display I, W and e information
4, log.w the meaning of Orange , can be seen as a warning warning, we generally need to pay attention to optimize the Android code, while selecting it will also output LOG.E information.
5, LOG.E is red, you can think of error errors, here only the red error message, these errors need our careful analysis, view the stack of information.
Note: Different printing methods are used with a method (string tag, string msg) parameter, tag is the label of the printed information, and MSG is the information that needs to be printed.
Here's a simple logdemoI made (step byStep):
Step 1: Prepare to work (open LogCat window).
Start Eclipse, window->show View will come up with a dialog box, when we click the Ok button, the console window will appear LogCat windows. For example:
Step 2: Create a new Android project, named Logdemo.
Step 3: design the UI interface, where we add a button to the button (click on the log log message).
The main.xml code is as follows:
[XHTML]View Plaincopy
- <? XML version= "1.0" encoding="Utf-8"?>
- <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- >
- <TextView
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:text="@string/hello"
- />
- <Button
- android:id="@+id/bt"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="Presse Me look Log"
- />
- </linearlayout>
Step 4: Design The main class Logdemo.java, the code is as follows:
[Java]View Plaincopy
- Public class Logdemo extends Activity {
- private static final String activity_tag="Logdemo";
- private Button BT;
- public void OnCreate (Bundle savedinstancestate) {
- super.oncreate (savedinstancestate);
- Setcontentview (R.layout.main);
- //Find the button resource through Findviewbyid
- BT = (Button) Findviewbyid (R.ID.BT);
- //Increase Incident Response
- Bt.setonclicklistener (new Button.onclicklistener () {
- @Override
- public void OnClick (View v) {
- LOG.V (Logdemo.activity_tag, "This is Verbose.");
- LOG.D (Logdemo.activity_tag, "This is Debug.");
- LOG.I (Logdemo.activity_tag, "This is Information");
- LOG.W (Logdemo.activity_tag, "This is warnning.");
- LOG.E (Logdemo.activity_tag, "This is Error.");
- }
- });
- }
- }
Step 5: Run the Logdemo project with the following results:
When we click on the button, it will trigger the event, which has the following effect in the Logcat window:
This article turns from http://blog.csdn.net/Android_Tutor/archive/2009/12/26/5081713.aspx
How to use Log text (LOG.V,LOG.D,LOG.I,LOG.W,LOG.E)