Using the Logcat command
The general usage of the command Logcat to view and track the system log buffers is:
[ADB] logcat [<option>] ... [<filter-spec>] ...
The filter and command options are described below, and details can be found in the listing of logcat command option.
You can use the Logcat command to view the log output in the development machine by using the remote shell:
$ adb Logcat
If you are using the command directly in the remote shell:
# Logcat
Filtering log output
Each log message has a tag and priority associated with it.
A token is a short string that identifies the source of the original message (for example, "View" originates from the display system).
The priority is the following character, in order from low to High:
V-Detail (lowest priority)
D-Debug
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 tags and priorities used in a system, the first two columns of the observation list, and the format given is <priority>/<tag>.
Here is a log output message, the priority is "I", the token is "Activitymanager":
I/activitymanager (585): Starting activity:intent {action=android.intent.action ...}
If you want to reduce the content of the output, you can add filter expression restrictions, the filter can limit the system to output only the tag-priority combination of interest.
The format of the filter expression is tag:priority ..., where tag is the token, priority is the minimum precedence, and the token identifies all messages that are greater than or equal to the specified priority level to be written to the log. You can also provide several such filters in a filter expression, separated by a space.
The example given below is only the output labeled "Activitymanager" and the priority is greater than or equal to "Info" and the log labeled "MYAPP" with a priority greater than or equal to "Debug":
ADB logcat activitymanager:i Myapp:d *:s
The last of the above expressions *:S
to set the log priority for all tags is s, which ensures that only the logs labeled "View" (the translator should be Activitymanager, the original text may be a clerical error) and "MyApp" are output, using *:S
is a recommended way to ensure that the output conforms to the specified filter settings, so that the filter becomes a "whitelist" of the log output.
The following expression shows all logs with priority greater than or equal to "warning":
ADB logcat *:w
If you are running on a development computer logcat
(as opposed to running a transport shell), you can also ANDROID_LOG_TAGS
set the default filter expression through environment variables:
Export android_log_tags= "activitymanager:i Myapp:d *:s "
It is important to note that if you run the remote shell or use the adb shell logcat
command logcat
, it ANDROID_LOG_TAGS
will not be exported to the emulator or mobile device.
Control log Format
Log messages have a number of metadata fields beyond the mark and priority, which can be controlled by modifying the output format to control the output, and -v
the options listed below control the output field:
brief-Show priority/tag and PID of the original process (default format)
process-Show only Process PID
tag-only show priority/tag
thread-Show only processes: threads and priorities/tags
raw-Display the original log information, no other metadata fields
time-display date, call time, priority/tag, PID
long-display all metadata fields and separate message contents with blank lines
You can use -v
startup logcat
to control the log format:
[ADB] logcat [-v <format>]
For example thread
, use the output format:
ADB logcat-v Thread
Note You can -v
specify only one format in the options.
viewing alternative Log buffers
The Android log system maintains multiple loop buffers for log messages, and not all messages are sent to the default buffers, and to view these additional buffers, you can use the -b
options, which are the buffers that you can specify:
radio-viewing buffer messages that are contained in a wireless/phone-related
events-viewing event-related messages
main-Viewing the 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
/*** @author Zhang Xingye * http://blog.csdn.net/xyz_lmn* my Sina Weibo:
@ Zhang Xingye tbow*/
ADB logcat viewing logs