Chapter 1 to do this, you must first use the Android SDK (6) and androidsdk

Source: Internet
Author: User

Chapter 1 to do this, you must first use the Android SDK (6) and androidsdk
1.6 Log printing-Log output tool (logcat)1.6.1Start logcat

It is not just Android development. For all software development, Log is very important. It is a friend we will inevitably access during the development and Debugging Processes, therefore, we must master the relationship with this friend.

In Android, the Android logging system supports recording and viewing system debugging information. Logs are recorded from various software and system buffers. You can use the logcat command to view and use logs in the buffer zone.

We can use the adb logcat command to run logcat:

Figure 1-32 run logcat

 

1.6.2 Filter log output

During Development and debugging, we often need to print logs for viewing. But sometimes it is a headache to find the information we need in a large number of logs. here we need to filter out the information we need in the log ocean.

Each Android log output has a tag and its priority.

The log tag is a brief identifier of the original information of the system component. (For example, "View" is to View the system tag ).

The priorities are listed in ascending order. The priorities are as follows:

V-Verbose (lowest priority)

D-Debug

I-Info

W-Warning

E-Error

F-Fatal

S-Silent (highest priority, on whichnothing is ever printed)

When running logcat, you can see the logcat label list and priority level in the first two columns. It is marked as follows: <priority>/<tag>, 1-33.

Figure 1-33 composition of logcat

 

Here we can see that its priority is D and the label is dalvikvm.

To enable log output to reflect the management level, you can also use filters to control log output. Filters can help you describe the system's tag level.

The filter statement uses the following format to describe the tag: priority... , Tag indicates the label, and priority indicates the lowest level of the label report. The log priority can be obtained from the above tag. You can write tag: priority multiple times in the filter, which is expressed by spaces.

The following filter statement shows the log information with a priority of Info or higher:
Adb logcat *: I

The effect is 1-34.

Figure 1-34 logcat Filtering

 

In this way, the log information with the priority of D is filtered out, and only the log information with the I level or above is displayed.

1.6.3 Control log output format

The log information includes many metadata fields. You can modify the log output format to display a specific metadata domain.

Logcat provides the following formats:

1) brief-default format. logs are displayed in the "priority/Tag (PID of the original process)" format;

2) process-log is displayed in the "priority (PID of the original process)" format;

3) tag-log is displayed in the "priority/tag" format;

4) The thread-log is displayed in the "priority (process number: thread number)" format;

5) raw-displays the original log information, and no other metadata fields exist;

6) time-log is displayed in the format of "time priority/Tag;

7) long-displays all metadata fields, and the information is separated by blank lines.

When logcat is started, we can use the-v option to specify the output format:

[Adb] logcat [-v <format>]

The following is the log format generated by Using thread:
Adb logcat-v thread

1-35.

Figure 1-35 control the logcat output format

 

1.6.4 View available log Buffers

The Android log system has a circular buffer, and not all log systems have a default circular buffer. To obtain the log information, you must use the-B Option to start logcat. To use a circular buffer, You need to view the remaining circular buffer:

Radio-view information about the buffer.

Events-view the Event-related buffer zone.

Main-view the main log Buffer

-How to Use Option B:

[Adb] logcat [-B <buffer>]

The following example shows how to view the log buffer that contains radio and telephony information:

Adb logcat-B radio

1-36.

Figure 1-36 view the buffer

 

Experience Sharing:

Processes started by the System in Android, STDOUT and STDERR (System. out and System. err) is directed to/dev/null. Therefore, the output of the program cannot be seen from the adb shell. It can only be printed through LOGW and then viewed through logcat.

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.