The Log tool class in Android is log (ANDROID.UTIL.LOG), which provides several ways for us to print the logs.
? LOG.V (): This method is used to print the most trivial, least meaningful log information. The corresponding level verbose is the lowest level in the Android log.
? LOG.D (): This method is used to print some debugging information that should be helpful for debugging programs and analyzing problems. The corresponding level of debug, higher than the verbose level.
? LOG.I (): This method is used to print some of the more important data, which should be very much wanted to see, can help analyze user behavior of the kind. corresponding level info, higher than Debug.
? LOG.W (): This method is used to print some warning messages, suggesting that the program may have potential risks in this place, and it is best to fix these warnings. Corresponds to level warn, one level higher than info.
? LOG.E (): This method is used to print error messages in a program, such as a program entering a catch statement. When the error message is printed, it usually means that your program has a serious problem and must be repaired as soon as possible. The corresponding level of error, higher than the warn level.
protected void onCreate (Bundle saveinstancestate) { super. OnCreate (saveinstancestate); LOG.D ("helloworldactivity", "onCreate execute"); LOG.I ("helloworldactivity", "onCreate execute"); LOG.W ("helloworldactivity", "onCreate execute"); LOG.E ("helloworldactivity", "onCreate execute");}
Log method passed two parameters, the first parameter when the tag, generally passed in the current class name is good, mainly used to filter the printing information. The second parameter is MSG, which is the specific content you want to print.
You can see not only the contents of the print log and the tag name, but also the package name of the program, the time of printing, and the process number of the application. If no information is printed in Logcat, it is possible that the current device has lost focus. This is only necessary to enter the Ddms view, click on the current device in the Devices window, the printing information will come out.
Use of filters
There are currently two filters, all Messeage filters are equivalent to no filtering, will show all the logs. Com.example.activitytest is that we run the Activitytest project is created automatically, click on this filter can only see the Activitytest program in the printed log.
Clicking on the "+" sign in the image will bring up a filter configuration screen. We name the filter data and let it filter the tag named data.
Click OK, there will be more than one data filter, when clicked on this filter, just in the OnCreate () method to print the log is gone, this is because the data filter will only display the tag named data log. The OnCreate () method can be tried to change the print log statement to LOG.D ("Data", "onCreate Execute"), and then run the program again, you will see the log under the data filter.
After reading the filter, look at the log level control in Logcat. There are 5 main levels in the Logcat, corresponding to the above 5 methods respectively.
When you select the verbose level, which is the lowest level, all verbose and above-level methods are printed.
Log tool for Android