Android adb logcat Command View log detailed description _android

Source: Internet
Author: User
Tags system log

Android developers will have to worry about log when they develop programs. Eclipse is not always log found, it is not very unpleasant, although the Logcat features of Android Studio is very good, but also not in the command line terminal printing more convenient.

Using the Logcat command

To view and track commands for the system log buffers the general usage of LOGCAT is:

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

The filters and command options are described below, and the details can be found in the listing of Logcat command options.

You can view log output using the LOGCAT command in a remote shell in your development machine:

$ adb Logcat

If you can use the command directly in a remote shell:

# Logcat

Filtering log output

Each log message has a tag and a priority associated with it.

A tag is a short string that identifies the source of the original message (for example, "View" originates from the display system).
Precedence is the following character, in order from low to High:

V-Detail (lowest priority)
D-Debugging
I-Information
W Warning
E-Error
F-Critical Error
S-no record (highest priority, nothing will be recorded)

By running Logcat, you can get a list of the tags and priorities used in a system, watch the first two columns of the list, and give a format of <priority>/<tag>.
Here is a log output message, the priority is "I" and the tag is "Activitymanager":

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

If you want to reduce the output of the content, you can add a filter expression to limit, the filter can limit the system output only interested tag-priority combination.

The format of the filter expression is tag:priority ..., where tag is the token, and the priority is the smallest priority, and the tag identifies all messages greater than or equal to the specified priority being written to the log. You can also provide multiple such filters in a filter expression, separated by a space.

The example given below is a log with only the output marked "Activitymanager" and the priority greater than or equal to "Info" and the priority greater than or equal to "Debug":

ADB logcat activitymanager:i Myapp:d *:s

The last *:s of the above expression is used to set the log priority of all tags to S, which ensures that only the log labeled "View" should be Activitymanager, the original may be a clerical error, and "MyApp" be exported, using *:s is a recommended way to ensure that the output conforms to the specified filter settings, so that the filter becomes the "whitelist" of the log output.

The following expression is a log showing all priority greater than or equal to "warning":

ADB logcat *:w

If you are running LOGCAT on a development computer (as opposed to running a shipping shell), you can also set the default filter expression through the ANDROID_LOG_TAGS environment variable:

Export android_log_tags= "activitymanager:i Myapp:d *:s "

Note that if you are running logcat in a remote shell or using the ADB Shell logcat command, Android_log_tags will not be exported to an emulator or mobile device.

Control log Format

Log messages have many metadata fields outside of the tag and priority that can control the output by modifying the output format, with the-v option plus the contents listed below to control the output fields:

brief-displays the precedence/markup and PID of the original process (default format)
process-only show Process PID
tag-Show priority/Tag only
thread-Show only processes: threads and priorities/tags
raw-Display the original log information, no more metadata fields
time-display date, call time, priority/tag, PID
long-displays all of the metadata fields and separates the message contents with blank lines

You can use the-V Startup Logcat to control the log format:

[ADB] logcat [-v <format>]

For example, use the thread output format:

ADB logcat-v Thread

Note You can specify only one format in the-v option.

viewing alternative Log buffers

The Android log system maintains multiple circular buffers for log messages, and not all messages are sent to the default buffer, and to view these additional buffers, you can use the-B option, which is the following buffer you can specify:

Radio-view included in wireless/phone-related buffer messages
events-View Event-related messages
main-View primary buffer (default buffer)

Use of the-B option:

[ADB] logcat [b <buffer>]

For example, view the radio buffer:

ADB logcat-b Radio
 

ADB Logcat Simple example:

1. Import log to SD card

Thank you for reading, I hope to help you, thank you for your support for this site!

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.