Android Log details (Log. v, Log. d, Log. I, Log. w, Log. e), log. vlog. d
InAndroidPeople in the group often ask me,Android LogHow is it used? Today I willSDKLet's get started quickly. I hope to get started with you.Android LogSome help.
Common android. util. Log methods include:5Items:Log. v () Log. d () Log. I () Log. w ()AndLog. e (). Corresponds to the first letterVERBOSE,DEBUG, INFO, WARN, and ERROR.
1. the debugging color of Log. v isBlack, Any message will be output. Here v stands for verbose, which is usually used as Log. v ("","");
2. The output color of Log. d isBlueOnly the meaning of debug debugging is output, but the upper-layer information is output, which can be selected through the Logcat tag of DDMS.
3. The output of Log. I isGreenGenerally, the prompt message information does not output the information of Log. v and Log. d, but displays the information of I, w, and e.
4. Log. w meansOrangeIt can be seen as a warning of warning. Generally, we need to optimize the Android code and select it to output Log. e information.
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.
Below is a simple exampleLogDemo(Step By Step ):
Step 1: Preparation (openLogCatWindows ).
StartEclipse, InWindow-> Show ViewA dialog box is displayed. When we clickOKButton appears in the console windowLogCatWindows. For example:
Step 2: CreateAndroidProject, namedLogDemo.
Step 3:DesignUIInterface, we addButtonButtonLogLog information ).
Main. xmlThe 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 classLogDemo. javaThe 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 bt = (Button) findViewById (R. id. bt); // Add the 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: RunLogDemoProject, the effect is as follows:
When you click the button, the event is triggered. The following results are displayed in the Logcat window: