Android Development Notes: Log Graphics (LOG.V,LOG.D,LOG.I,LOG.W,LOG.E) _android

Source: Internet
Author: User

InAndroidGroup, people often ask me,Android LogHow it's used today I'm going to take it from the Internet as wellSDKIn the patchwork, let everyone first glimpse as fast, I hope to get startedAndroid LogThere is a certain amount of help.
Android.util.Log commonly used methods are the following5A:log.v () log.d () log.i () LOG.W ( )and log.e () . According to the first letter VERBOSE,DEBUG,INFO, WARN,ERROR.
1, log.v debugging color is black , any message will be output, where the V represents verbose long-winded meaning, peacetime use is LOG.V ("", "");
2, LOG.D output color is blue , only output debug debugging meaning, but he will output the upper level of information, filtered through the DDMS logcat tag to choose.
3, LOG.I output is Green , the 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 meaning of Orange , can be seen as warning warning, generally require us to focus on optimizing the Android code, and select 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, look at the stack of information.
Here's a simple logdemoI made:
Step 1: Prepare for Work (open logcat window).
Start Eclipse, a dialog box will come out in window->show View , and when we click the Ok button, it will appear in the console window logcat Windows. The following figure:

Step 2: Create a new Android project, named Logdemo.
Step 3: design UI interface, we add a button buttons here ( Click the button to appear log information).
The main.xml code is as follows:

Copy Code code as follows:

<?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:
Copy Code code as follows:

Package com.android.test;
Import android.app.Activity;
Import Android.os.Bundle;
Import Android.util.Log;
Import Android.view.View;
Import Android.widget.Button;
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 event 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, the effect is as follows:



When we click on the button, it triggers the event, which has the following effect under the Logcat window:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.