How to control the custom output of LogCat in Android, androidlogcat

Source: Internet
Author: User

How to control the custom output of LogCat in Android, androidlogcat

In Android development, LogCat is a very important debugging tool that can output a lot of information about projects or mobile phones. However, because the LogCat function is too powerful and the output information is extremely large, we need to limit the LogCat output according to our needs in a certain way, in this way, LogCat can help us better debug code.

Generally, there are five types of LogCat output: verbose, debug, info, warn, and error. Among them, verbose is the most extensive. If verbose is selected, verbose, debug, info, warn, and error will be output backward compatible. If debug is selected, debug, info, warn, and error are output backward compatible. And so on. Generally, you can select the debugging area below Eclipse. :

.


When the Log method is used in the Code for output, you can also control the output of different content. There are also five different Log methods. Log. v ("",""). log. d ("",""). log. I ("",""). log. w ("",""). log. e ("","").. in actual development, you can print the output according to your needs.

In fact, we can not only control and display these five categories of logs through tag selection or method selection, but also provide us with precise Log search in Android. As shown in: "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, project package name, tag, and text output. In addition, dynamic modification and display can be performed here. Very convenient. Let me present them one by one.

.


(1) Use the pid process ID to limit the output

If your workspace contains multiple projects and multiple projects are running continuously, the printed content in your LogCat may contain multiple different projects, of course, the process IDs of different projects are different, so we can limit the output by ID.

Before output control:

.


The output is controlled by pid: 5344 process ID. Because I can use the task manager or roughly browse the LogCat output to know the process ID of the current application. The following is the output result of pid: 5344 control. The result is obviously reduced. We can easily observe the output results of this project.

.


(2) Use the full name of the app package to restrict output

The app name is more accurate than the package name to limit the output. The package name can also uniquely identify an application.

Before output control:

.


Control the output through the application package name app: com. example. logcatdemo. Note that the life-saving must be the complete package name.

.



(3) Use tag tags to limit output

When you use the Log Method for printing. Log. I ("tag", "Print value"). The first parameter is the tag. You can use the tag: tag value to uniquely identify an output, accurate to a specific output.

Output result after tag control:
.



(4) use output text to limit output

If you already know what will be output during the debugging process, you can directly control the display through text search, for example, my output is "LogCat test output ", I can restrict it:

.



The above four methods can be used to dynamically search for the output, which is more convenient. Of course, you can also click the green plus sign on the left side to perform Log control in the pop-up dialog box. The implementation methods are the same as above .. You can try it yourself.

.


Mastering Log output and LogCat debugging will greatly improve our development efficiency.



Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.