Android Logcat Detailed Usage

Source: Internet
Author: User

admin| 2011-10-29 11:16| Category: Learning Documents | Android Logcat | Comments: [0]|

The Android log system provides the ability to record and view system debug information. Logs are recorded from a variety of software and some system buffers, and buffers can be viewed and used by the Logcat command.

Using the Logcat command

You can use the Logcat command to view the contents of the System log buffer:
[ADB] logcat [<option>] ... [<filter-spec>] ...
Please see the listing of Logcat command Options, which have a detailed description of the Logcat commands.

You can also use the LOGCAT command on your computer or the remote ADB shell running on the emulator/device, or you can view the log output on your computer.
$ adb Logcat
You also use this:
# Logcat

Filtering log output

Each output of the Android log information has a label and its priority.
The label of the log is a brief indication of the original information of the system part. (For example, "View" is to view the system's label).
Priority has the following concentrations, which are arranged smoothly from low to High:
V-verbose (Lowest priority)
D-debug
I-info
W-warning
E-error
F-fatal
S-silent (highest priority, on which nothing is ever printed)
In the first two columns when you run Logcat, you can see the LOGCAT tag list and priority level, which is the:<priority>/<tag>.

Here is an example of a logcat output, which has the precedence of I, the tag is activitymanage:

I/activitymanager (585): Starting activity:intent {action=android.intent.action ...}

In order for the log output to reflect the level of management, you can also use filters to control the log output, and filters can help you describe the system's label level.

Filter statements are described in the following format tag:priority ..., tag is a label, priority is the lowest level of reporting for the label. The priority of the log can be obtained from the above tag. You can write tag:priority multiple times in the filter.

These instructions are only to the blank end. Here is an example that shows support for all log information except those labeled "Activitymanager" and the priority "Info" above and labeled "MYAPP" and Priority "Debug" above. The priority report is the tag.

ADB logcat activitymanager:i Myapp:d *:s

The last element of the expression above *:s, is to set all the labels as "silent", all the logs are only shown with "View" and "MyApp", another use of *:s is to be able to ensure that the log output is in accordance with the filter description limit, Also let the filter output to the log as an item.

The following filter statements refer to log information that shows priority warning or higher:
ADB logcat *:w

If you run Logcat on your computer, you can also android_log_tags for environment variables: Enter a parameter to set the default filter, compared to the remote Adbshell side.
Export android_log_tags= "activitymanager:i Myapp:d *:s "

It is important to note that the Android_log_tags filter cannot output the log if it runs logcat through the remote shell or runs the emulator/device with the ADB shell logcat.

Control log Output format

The log information includes many metadata fields including labels and precedence. You can modify the output format of the log so that a specific metadata field can be displayed. Information about the formatted output log can be obtained through the-v option.

Brief-display Priority/tag and PID of originating process (the default format).
Process-display PID only.
Tag-display the Priority/tag only.
Thread-display Process:thread and Priority/tag only.
Raw-display the raw log message with and no other metadata fields.
Time-display the date, invocation time, Priority/tag, and PID of the originating process.
Long-display all metadata fields and separate messages with a blank lines.

When Logcat is started, you can specify the output format with the-V option:
[ADB] logcat [-v <format>]

Here is the log format generated with thread:
ADB logcat-v Thread

Note that you only have the-V option to specify the output format options.

View available Log buffers

The Android log system has a loop buffer, and not all log systems have a default loop buffer. In order to get the log information, you need to start logcat with the-B option. If you want to use a loop buffer, you need to see the remaining loop buffer period:

radio-View the information about the buffer.
events-view the buffer associated with the event.
main-viewing the primary log buffer

The-B option uses the method:
[ADB] logcat [-b <buffer>]

The following example shows how to view the log buffer containing radio and telephony information:
ADB logcat-b Radio

View stdout and stderr

By default, the Android system has stdout and stderr (System.out and System.err) output to/dev/null, and in the process of running the Dalvik VM, a system can back up the log files. In this case, the system uses stdout and stderr and the priority I to record the log information.

This method specifies the path to the output, stops the emulator/device running, and then remotely enters the log by using the SetProp command

$ adb shell stop
$ adb shell SetProp Log.redirect-stdio true
$ adb shell start

System until you turn off the simulator/device before the settings are retained, you can use the default settings on the emulator/device by adding/data/local.prop

Logcat Command List

Option
Description

b <buffer>
Load a log buffer that can be used for viewing, such as event and radio. The default value is main. See Viewing alternative Log buffers specifically.

-C
Clear the Log on the screen.

-D
Output the log to the screen.

-F <filename>
Specifies the <filename> of the output log information, which is stdout by default.

-G
Outputs the specified log buffer and exits after output.

-N <count>
Set the maximum number of logs <count>., the default value is 4 and needs to be used with the-r option.

-R <kbytes>
Output log per <kbytes>, default value is 16 and needs to be used with the-f option.

-S
Set the default filter level to silent.

-V <format>
To set the log input format, the default is brief format, to know more supported formats, see Controlling log Output format.

Android Logcat Detailed Usage

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.