Using the new version of Android Studio Logcat

1. Logcat startup
When the application starts or stops (closes or crashes), the new logcat will display additional messages. It will contain the new message, process ID, and package name.

2. Logcat search
Logcat provides a search bar with very rich search logic. Let’s talk about the content we use more:

1. Search the logs under the current package name:

package:mine 


2. Add log level.
There are 6 log levels in total. Log level: level:[VERBOSE | INFO | ASSERT | DEBUG | WARN | ERROR]. If I want to find logs >= INFO level:

package:mine level:info 


3. Add tags
to find logs with a specific tag (tag). For example, you need to find logs containing the "info" tag:

package:mine level:info tag:info


4. Label + field
For example, there is the following log:

Log.i("info","info tag one")
Log.i("info","info tag two")
Log.i("info","info tag three")

Now we need to query the logs with the "one" field:

package:mine level:info tag:info one


5. Exclude fields

Log.i("info","info tag one")
Log.i("info2","info tag two")
Log.i("info3","info tag three")

Now get "info" and need to exclude logs containing "info2":

package:mine level:info tag:info -tag:info2


6. Use regular expressions.
If the following log exists:

Log.i("info","info tag one")
Log.i("info2","info tag two")
Log.i("info3","info tag three")

Need to obtain tag logs starting with "info":

package:mine tag~:info*


7. Use regular expressions to exclude

Log.i("info","info tag one")
Log.i("info2","info tag two")
Log.i("info3","info tag three")

Need to get logs that do not end with "2":

package:mine level:info -tag~:.*2


 8. Use age to intercept time

age:30s returns the last 30 seconds of logs
age:2m returns the last 2 minutes of logs
age:1h returns the last hour of logs
age:2d returns the last 2 days of logs

package:mine age:10s

9. Query multiple keywords


For example, if I want to get the three keywords "aa", "bb" and "cc" at the same time, I need to use "|", similar to this:

package:mine aa | bb | cc

Tips: Note that keywords need to be separated by spaces!

3. Logcat Collection
Logcat will record the log commands you have written, which can be queried in the history:

For some commands that you care about or like, add them to your favorites:

After the collection is completed, it can be displayed in the history list:


4. Logcat formatting
can be done by clicking the tool on the left side of Logcat:

Enter "Standard View", you can display timestamp (date and time), process ID (including thread ID), label, package name, log level and message, etc., of course, it also supports customized configuration, hope it displays Whatever, just tick whatever:

When entering "Compact View", that is, compact View, the timestamp (time), log level and message are displayed.

After the modification is completed, you can see our beautiful log output.

5. Supports multi-window mode.
The new version of Logcat supports multi-window operation mode, which is quite powerful.


6. Summary
The basic commonly used functions have been mentioned once. Generally speaking, the new version of Logcat has some new functions compared to the old version of Logcat:

Additional logs when the application starts, stops or crashes
Multiple logcat tabs and windows allow users to analyze data from different devices simultaneously
Formatting options for log entries can be adjusted and we can see filtered information
Searches and filters are merged to always be visible The query input field also includes additional filter operators.
Most of the available queries can be saved as favorites, and you have greater control over query history.

Original link: https://blog.csdn.net/u013762572/article/details/130085340 

Guess you like

Origin blog.csdn.net/weixin_62302176/article/details/132724075