Document directory
- Filter log output
- Control log output format
- View available log Buffers
- View stdout and stderr
The android logging system allows you to record and view system debugging information. Logs are recorded from various software and system buffers.logcatCommand to view and use.
Use the logcat command
You can uselogcatCommand to view the content of the System Log Buffer:
[adb] logcat [<option>] ... [<filter-spec>] ...
Please refer to the listing of logcat command options, which provides a detailed description of the logcat command.
You can also use it on your computer or on the remote ADB shell terminal running on the simulator/device.logcatCommand, you can also 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 to view the system tag ).
- 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)
You can see the information in the first two columns when running logcat.logcatLabel list and priority level, which are marked as follows:<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 is described in the following format:tag:priority ...,tagIndicates a tag,priorityIs the lowest level of the label report. The log priority can be obtained from the above tag. You can write it multiple times in the filter.tag:priority.
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
Last element of the above expression*:S, Is to set all labels as "silent", all logs only show "View" and "MyApp",*:SAnother use is to ensure that the log output is restricted according to the instructions 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 runlogcatCompared with remote adbshell, you can also use environment variablesANDROID_LOG_TAGS: Enter a parameter to set the default filter.
export ANDROID_LOG_TAGS="ActivityManager:I MyApp:D *:S"
Note thatANDROID_LOG_TAGSIf the filter runs through a remote shelllogcatOr useadb shell logcatThe simulator/device cannot output logs.
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-vOption to obtain information about the formatted output log.
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.
Whenlogcat, You can-vTo specify the output format:
[adb] logcat [-v <format>]
UsethreadTo generate the log format:
adb logcat -v thread
Note that you can only-vSpecifies the output format.
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 need-bOption to startlogcat. 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 major log Buffers
-bOption usage:
[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 hasstdoutAndstderr(System.outAndSystem.err) Output/dev/nullIn the process of running Dalvik Vm, a system can back up log files. In this case, the system will usestdoutAndstderrAnd priority I. To record log information
In this way, specify the output path, stop the running simulator/device, and then usesetpropCommand Remote input log
$ 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.propYou can use the default settings on the simulator/device.
Logcat command list
| Option |
Description |
-b <buffer> |
Load an available log buffer for viewing, sucheventAndradio. The default value ismain. For details, see viewing alternative log buffers. |
-c |
Clear the logs on the screen. |
-d |
Output logs to the screen. |
-f <filename> |
Specify<filename>The default value isstdout. |
-g |
Output the specified log buffer and exit after the output. |
-n <count> |
Set the maximum number of logs<count>. The default value is 4.-rOption. |
-r <kbytes> |
Each<kbytes>Logs are output. The default value is 16.-fOption. |
-s |
Set the default filtering level to silent. |
-v <format> |
Set the log input format. The default format isbriefFor more supported formats, see controlling log output format. |