Android new version Logcat operation tips

The new Logcat is enabled in the new version of Android Studio. Here are some tips:

1. Logcat starts

The new logcat displays additional messages when the application starts or stops (shuts down or crashes). It will contain the new message, process ID, and package name.

Insert image description here

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 

Insert image description here

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 

Insert image description here

3. Add tags

You need to find logs with specific tags, for example, you need to find logs containing the "info" field:

package:mine level:info tag:info

Insert image description here

4. Label+Field

For example, the following log exists now:

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

Insert image description here

5. Exclude fields

For example, there are three logs:

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

Insert image description here

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*

Insert image description here

7. Use regular expressions to exclude

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 get logs that do not end with " 2 ":

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

Insert image description here

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

Insert image description here

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

Insert image description here
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 found in the history records:
Insert image description here
For some commands you care about or like, add them to your favorites:
Insert image description here
After collecting them, you can display them in the history list:
Insert image description here

4. Logcat formatting


Insert image description here
You can enter the " Standard View " by clicking the tool on the left side of Logcat: you can display the timestamp (date and time), process ID (including thread ID), label, package name, log level and message, etc., of course, it It also supports customized configuration. Just check what you want it to display:
Insert image description here
enter " Compact View ", that is, when you enter Compact View, the timestamp (time), log level and message are displayed.
Insert image description here
After the modification is completed, you can see our beautiful log output.

5. Support multi-window mode

The new version of Logcat supports multi-window operation mode, which is quite powerful. I personally find it very easy to use:
Insert image description here

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:

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

That's basically it. If you have any questions while learning and using it, you can contact me wx: javainstalling, note: Logcat.

Guess you like

Origin blog.csdn.net/u013762572/article/details/130085340