In Android development, Logcat is a very important debugging tool that can output a lot of information about projects or mobile phones. But precisely because the Logcat function is too powerful, the output of the amount of information is extremely large, then we need a certain way according to our needs to limit the output of logcat, so as to enable Logcat to help us play a better role in debugging code.
There are generally five types of logcat output, namely Verbose,debug,info,warn,error. The verbose is the most broad, if you choose Verbose, then it will be backwards compatible with the output verbose,debug,info,warn,error. If Debug is selected, it is backwards compatible with the output debug,info,warn,error. And so on You can typically choose from the debug area below Eclipse. :
。
When you use the log method in your code to output, you can also control the output of different content. There are also 5 different log methods for the corresponding. LOG.V ("", ""). LOG.D ("", ""). LOG.I ("", ""). LOG.W ("", ""). LOG.E ("", ""). In actual development, different printouts can be made according to their own needs.
In fact, not only through the choice of the label, or the choice of methods, to the five categories of log control display, Android also provides us with a precise log lookup. As shown: "Search for messages." Accepts Java regexes. Prefix with pid:,app:,tag:or text:to limit scope. That is, we can limit the output range by using the process ID, the project package name, the tag tag, and the text output. And here you can make dynamic changes, dynamic display. Very convenient. Let me show you the same.
。
(1) Limit output with PID process ID number
If you currently have multiple projects in your workspace, and multiple projects are constantly running, the content printed in your logcat may contain several different projects, of course, the process IDs of different projects are different, and we can limit the output by ID.
Before output control is performed:
。
Control the output by pid:5344 the process ID. Because I can use the Task Manager or roughly browse the logcat output to know what the current process ID is for this application. The following is the result of the pid:5344 control output. The findings are significantly less. It is convenient for us to observe only the output of this project.
。
(2) Limit output with app package name
Using the app's name is more accurate than the package name to limit the output. The package name can also uniquely identify an application.
Before output control is performed:
。
Control output through the application package name App:com.example.logcatdemo, note that the insurance must be the full package name.
。
(3) Limit output with tag tag
When you print using the log method. LOG.I ("label", "Print Value"), the first parameter is the tag tag, you can use tag: Tag value, to uniquely identify an output, accurate to a specific output.
Output after tag control:
。
(4) Limit output with output text
If you already know what to export during debugging, you can display control directly through text lookup, such as my output is "logcat test output" and I can limit it:
.
Through the above four ways can be dynamic output of the search, it is more convenient. Of course, you can also click on the left side of the Green Plus, in the Pop-up dialog box log control is also possible, the implementation of the same 4 kinds of. You can try it on your own, please.
。
Proficiency in the use of log output and Logcat debugging will greatly improve our development efficiency.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
How to control the custom output of Logcat in Android