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.logcat
Command to view and use.
Use the logcat command
You can uselogcat
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 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.logcat
Command, 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.logcat
Label 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 ...
,tag
Indicates a tag,priority
Is 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",*:S
Another 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 runlogcat
Compared 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_TAGS
If the filter runs through a remote shelllogcat
Or useadb shell logcat
The 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-v
Option 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-v
To specify the output format:
[adb] logcat [-v <format>]
Usethread
To generate the log format:
adb logcat -v thread
Note that you can only-v
Specifies 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-b
Option 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
-b
Option 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 hasstdout
Andstderr
(System.out
AndSystem.err
) Output/dev/null
In the process of running Dalvik Vm, a system can back up log files. In this case, the system will usestdout
Andstderr
And priority I. To record log information
In this way, specify the output path, stop the running simulator/device, and then usesetprop
Command 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.prop
You can use the default settings on the simulator/device.
Logcat command list
Option |
Description |
-b <buffer> |
Load an available log buffer for viewing, suchevent Andradio . 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.-r Option. |
-r <kbytes> |
Each<kbytes> Logs are output. The default value is 16.-f Option. |
-s |
Set the default filtering level to silent. |
-v <format> |
Set the log input format. The default format isbrief For more supported formats, see controlling log output format. |