Android ADB logcat command view log details

When Android programmers develop programs, they must have been distressed by log. Isn't it annoying that eclipse can't find the log all the time? Although the logcat function of Android studio is very good, it's not more convenient to print it in the command line terminal.

Using the logcat command

The general usage of the command logcat to view and track the system log buffer is:

The filter and command options are described below. For details, see Listing of logcat command options.

You can use the logcat command to view the log output through a remote shell in the development machine:

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

Filter log output

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

A tag is a short string that identifies the source of the original message (for example, "view" comes from the display system). The priority is the following characters, from low to high:

@H_ 403_ 44@V -- details (lowest priority) d -- debugging I -- information w -- warning e -- error F -- serious error s -- no record (highest priority, nothing will be recorded)

By running logcat, you can get a list of tags and priorities used in the system. Observe the first two columns of the list. The format given is < priority > / < tag >. Here is a log output message with priority "I" and mark "activitymanager":

If you want to reduce the output content, you can add a filter expression to restrict it. The filter can restrict the system to output only the tag priority combination of interest.

The format of the filter expression is tag: priority... Where tag is the tag and priority is the minimum priority. All messages identified by the tag greater than or equal to the specified priority are written to the log. You can also provide multiple such filters in a filter expression, separated by spaces.

The following example is to output only logs marked "activitymanager" with priority greater than or equal to "info" and "myapp" with priority greater than or equal to "debug":

The *: s at the end of the above expression is used to set the log priority of all tags to s, which can ensure that only the logs marked "view" and "myapp" are output. Using *: s is a recommended way to ensure that the output meets the specified filter settings, In this way, the filter becomes the "white list" of log output.

The following expression shows all logs with priority greater than or equal to "warning":

If you run logcat on a development computer (as opposed to running an express shell), you can also use Android_ LOG_ The tags environment variable sets the default filter expression:

It should be noted that if you run logcat in a remote shell or using the ADB shell logcat command, Android_ LOG_ Tags will not be exported to the simulator or mobile device.

Control log format

In addition to the tag and priority, log messages also have many metadata fields. These fields can control the output results by modifying the output format. The - V option plus the contents listed below can control the output fields:

@H_ 403_ 44@brief - display priority / tag and PID of original process (default format) process - display only process PID tag - display only priority / tag thread - display only process: thread and priority / tag raw - display original log information without other metadata fields time - display date, call time, priority / tag, PID long -- displays all metadata fields and separates the message content with a blank line

You can use - V to start logcat to control the log format:

For example, use thread output format:

Note that only one format can be specified in the - V option.

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

Radio -- view messages contained in the wireless / telephone related buffer events -- view messages related to events main -- view the main buffer (default buffer)

-Usage of B option:

For example, to view the radio buffer:

Simple example of ADB logcat:

1. Import logs to SD card

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

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>