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 classLogdemoExtends 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: RunLogdemoProject, the effect is as follows:
When you click the button, the event is triggered. The following results are displayed in the logcat window: