Android intermediate course ---- Log graphic explanation (Log. v, Log. d, Log. I, Log. w, Log. e )!

Source: Internet
Author: User

In the Android group, people often ask me how to use the Android Log. Today, I am trying to get everything from the Internet and the SDK, so that everyone can get started quickly, we hope to help you get started with Android Log.

Common android. util. Log methods include Log. v () Log. d () Log. I () Log. w () and Log. e (). Corresponds to VERBOSE, DEBUG, INFO, WARN, and ERROR according to the first letter.

1. the debugging color of Log. v is black, and any message will be output. Here v stands for verbose, which is usually used as Log. v ("","");

2. The output color of Log. d is blue and only the meaning of debug debugging is output. However, it outputs the upper-layer information, which can be selected through the Logcat tag of DDMS.

3. The output of Log. I is green. Generally, it indicates message information. It does not output information of Log. v and Log. d, but displays information of I, w, and e.

4. Log. w indicates orange. It can be seen as a warning of warning. Generally, we need to optimize the Android code and select it to output Log. e.

5. If Log. e is red, you can think of error errors. Here, only red error messages are displayed. We need to carefully analyze these errors and view stack information.

The following is a simple LogDemo (Step By Step) I have created ):

Step 1: Prepare (open the LogCat window ).

Start Eclipse. A dialog box is displayed in Window-> Show View. When you click OK, The LogCat Window appears in the console Window, for example:

 

 

 

 

Step 2: Create an Android project named LogDemo.

 

Step 3: design the UI. Here we add a Button (click the Button to display the Log information ).

The Main. xml Code is 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:

 

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 );
// Add 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 you click the button, the event is triggered. The following results are displayed in the Logcat window:

 

 

 

 

 


From Android_Tutor's column

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.