I know that our blog Park big God, see this blog will be sniffed, but I still want to write down this blog post, because the first time I touched the logcat really is put down, really is too easy to use, so I would like to share to the new students to join the android.
Learn Java all know print log with System.out.println (), but in the real project development but very disapproved of the use of this, why? It's really useless to me except for the convenience of use. Log printing is not controllable, time can not be determined, there is no security level, can not add filters ...
Well, with all the shortcomings of this old method, what's logcat better than that?
First of all, Logcat is divided into 5 levels, below we from low to high introduction:
LOG.V (): It is generally used to print information of small meaning and trivial information.
LOG.D (): This is usually used when debugging a program.
LOG.I (): This is used to print some information more important content.
LOG.W (): Obviously, this is about printing some warning messages.
LOG.E (): Usually a serious problem will be printed out with him.
So see, is not at a glance, sure enough than System.out.println (); Tall on the point, but, this is not the real NB, its most powerful feature is: Log filtering function.
In general, there will be at least 1 filters under the Logcat screen, one is allmessages, and the other is the project package name filter you created. The Allmessages filter will print all the information logs from your phone, whether it's a log of your own project or not, whether it's what you want or not. However, a filter with the name of the package name will only print the log of the item that is currently owned. Isn't it amazing?
Let's configure a filter on our own:
On the left side of the logcat screen, there is a small + sign that pops up a dialog box called Logcat messages filter setting, where we write our name for this filter in the filter name and then the by log tag to write a string or symbol for identifying a class such as: "=============" or "MYLOG-2016-05-12: Debug Server Connection Status:" And so on ... Fill it out, then click OK and we'll go to the project and add the log.
To the place where we want to print the log in our project, we add this code: LOG.D ("mylog-2016-05-12: Debug Server Connection Status:", "Debug:" +messages), and then run the project. When the program runs to this code, it prints what's inside it.
Well, is it very useful? The example is not written, I am here knowledge tells you can use, want to know specifically to move to write a try, my knowledge tells you have such a thing.
OK, no more say, good night!
Add a digression: One of the great gods has said that if you do not work in a place, or if you feel that your salary is too low, it is time for you to leave.
The use of Android little tricks logcat