Explanation of the android logcat command: Translation of enabling logcat Logging

Source: Internet
Author: User

Detailed explanation of Android logcat commands

-- Translation enabling logcat Logging

Tian haili @ csdn

The android log system provides the function of collecting and viewing system debugging output. Logs output by various applications and other components of the system are stored in some cyclic buffers, which can be viewed and filtered using the logcat command.

Use the logcat command

You can use the logcat command to view and control the content in the System Log buffer. The common usage is as follows:

[ADB] logcat [<option>]... [<filter-spec>]...

The following sections describe filtering and Command Options. For a comprehensive summary of the options, see the logcat Command Option List.

You can use the logcat command on your computer or by running the remote ADB shell on the simulator/device. View log output on your computer:

$ ADB logcat

The remote ADB shell can be used as follows:

# Logcat

Filter log output

The android log information has a tag and its priority (priority ).

· The log label is a brief description to indicate the system component in which the log is written. (For example, "View" is the view system label ).

· The priorities are listed in the following order:

O v-verbose (lowest priority)

O d-Debug

O I-Info

O w-warning

O e-Error

O f-fatal

O s-silent (highest priority, no output)

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

The following is an example of logcat output. Its priority is "I" and the label is "activitymanage ":

I/activitymanager (585): starting activity: intent {Action = Android. Intent. Action ...}

You can also useFilterTo limit log output. The filter can only display the information of the tag-priority combination you are interested in, while hiding other information.

The a filter statement is described in the format of Tag: priority. Here, tag indicates the tag of interest, and priority indicates the tag specified in the report.LowestLevel. Information containing the above tag or information above the specified priority is written into the log. You can provide multiple Tag: Priority declarations in a filter expression. These declarations are separated by blank spaces.

The following is an example of a filter expression that does not display all other log information, in addition to the information with "activitymanager" and "info" or higher as "MyApp" and with a higher priority than "debug.

ADB logcat activitymanager: I MyApp: D *: S

The last element *: s of the above expression is to set the priority of all labels to "silent", so that only the logs of "View" and "MyApp" are displayed. Use *: S is an excellent way to ensure that the log output is limited to the filter expression you explicitly specify -- it makes your filter like a "White List" in log output ".

The following filter statement displays log information with a priority of warning or higher:

ADB logcat *: W

If you run logcat on your computer (compared to remotely running ADB shell), you can also set the default filter by specifying a parameter for the environment variable android_log_tags:

Export android_log_tags = "activitymanager: I MyApp: D *: S"

Note that if you run logcat remotely or use ADB shell logcat, The android_log_tags filter cannot be applied to simulators/device instances.

Control log output format

In addition to tags and priorities, log information also contains many other metadata fields. You can modify the log output format to display a specific metadata domain. You can use the-V option to specify the following supported formatting outputs.

· Brief-Display priority/Tag and PID of the log printing process (default format ).

· Process-only display PID ..

· Tag-only display priority/Tag.

· Thread-display process: thread and priority/Tag.

· Raw-displays the original log information and does not display other metadata fields.

· Time-display date, occurrence time, priority/tag, and PID of the log printing process.

· Long-displays all metadata domains and log information, which are separated by blank lines.

When logcat is started, you can use the-V option to specify the output format:

[ADB] logcat [-v <format>]

The following is an example of a log generated using the thread output format:

ADB logcat-V thread

Note that you can only use the-V option to specify an output format.

View the specified log Buffer

The android log system has multiple cyclic buffers. Not all log information outputs logs to the default cyclic buffer. To view the log information of other buffers, you must use the-B Option to start logcat. Look at other circular buffers. These buffers are:

· Radio-view information in the buffer zone related to wireless/telephone.

· Events-view the Event-related buffer zone.

· Main-view logs in the main buffer (default)

-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

View stdout and stderr

By default, the android system outputs stdout and stderr (system. Out and system. Err) to/dev/null. In the process of running Dalvik Vm, a system can back up log output. In this case, the system uses stdout, stderr, and priority I. To record log information.

In this way, specify the output path. You can stop the running simulator/device and use the setprop command to redirect the output.

$ ADB shell stop
$ ADB shell setprop log. Redirect-stdio true
$ ADB shell start

The system keeps these settings before you turn off the simulator/device. To use this setting as the default setting for your simulator/device, you can add it to the file/data/local. prop of the device.

Logcat Command Option List

Option

Description

-B <buffer>

Load a specified log buffer for viewing, such as event or radio. The default value is main. For details, refer to view the specified log buffers.

-C

Clear the entire log and exit.

-D

Output the log to the screen and exit.

-F <FILENAME>

Write the log information to <FILENAME>. The default value is stdout.

-G

Print the size of the specified log buffer and exit.

-N <count>

Set the maximum number of logs <count>. The default value is 4. It must be used with option-R.

-R <Kbytes>

Rotates writes the log file for each output of <Kbytes>. The default value is 16, which must be used with option-f.

-S

Set the default filtering level to silent.

-V <format>

Sets the log output format. The default format is brief. For more supported formats, see control log output format.

 

//////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// /////////////////////////////////////

See the two edited results in word:

I. Start

Ii. End

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.