[Detailed usage of Android logcat]

Source: Internet
Author: User

The android logging system allows you to record and view 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.

Use the logcat command
You can use the logcat command to view the content of the System Log Buffer:

[ADB] logcat [<option>]... [<filter-spec>]...
Please refer to the listing of logcat command options, which has a detailed description of the logcat command.

You can also use the logcat command on your computer or remote ADB Shell Running on the simulator/device, or view the log output on your computer.

$ ADB logcat
You can also use the following method:

# Logcat

Filter log output
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 used to view system labels ).
The priority has the following sets, 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)
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 ...}
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 depicts the tag in the following format: priority ..., the tag table indicates the label, and the priority indicates the lowest level of the label report. the log priority can be obtained from the above tag. you can write the tag: Priority multiple times in the filter.

All of these instructions end with a blank space. The following example shows a column that supports all log information, except for those with "activitymanager" and "info" or above, and those with "MyApp" and "debug" or higher priorities. Level. The priority report is tag.

ADB logcat activitymanager: I MyApp: D *: S
The last element *: s of the above expression is to set all labels as "silent", and all logs only show "View" and "MyApp". Use *: another use of S is to ensure that the log output is restricted according to the description of the filter, and make the filter output to the log as an item.

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

ADB logcat *: W
If you run logcat on your computer, you can also set the default filter for the environment variable android_log_tags:

Export android_log_tags = "activitymanager: I MyApp: D *: S"
It should be noted that if the android_log_tags filter runs logcat through a remote shell or runs the simulator/device using ADB shell logcat, logs cannot be output.

Control log output format
Log information includes many metadata fields, including tags and priorities. You can modify the log output format to display a specific metadata domain. You can use the-V option to obtain information about formatted output logs.

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 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 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
Note that you can specify the output format option only with the-V option.

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 the cyclic buffer, you need to check the remaining cyclic buffer period:

Radio-view information about the buffer.
Events-view the Event-related buffer.
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

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

In this way, specify the output path, stop the running simulator/device, and use setprop to remotely enter logs.

$ ADB shell stop $ ADB shell setprop log. Redirect-stdio true $ ADB shell start
The system is retained until you disable the simulator/device. You can add/data/local. Prop to use the default settings on the simulator/device.

Logcat command list
Option description
-B <buffer> loads an available log buffer for viewing, such as event and radio. The default value is main. For details, see viewing alternative log buffers.
-C: Clear the logs on the screen.
-D. output the log to the screen.
-F <FILENAME> specifies the <FILENAME> of the output log information. The default value is stdout.
-G outputs the specified log buffer and exits after the output.
-N <count> set the maximum number of logs <count>. The default value is 4, which must be used with the-r option.
-R <Kbytes> outputs logs per <Kbytes>. The default value is 16 and must be used with the-F option.
-S sets the default filtering level to silent.
-V <format> sets the log input format. The default format is the brief format. For more supported formats, see controlling log output format.

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.