background

First of all, to view Android logs, you need to install ADB environment, and then through ADB command to view in the terminal, developers ide tool terminal has been very convenient for us to filter and filter logs. But using Cygwin instead of CMD is highly recommended because the windowd experience is notoriously poor. What is Cygwin? Cygwin is a Unix-like simulation environment running on Windows platform, which means that you can use Linux commands under Windows after installing Cygwin. Some commands that cannot be used under CMD can be used under Cygwin, such as grep, color, etc. This article only covers some ADB directives, but you can learn more about them if you are interested.

This article object-oriented is QA (and too lazy to open the ide see log android developer), because developers will often add a lot of log in code for debugging, if QA can observe the log printout when encounter a bug (filter conditions according to the developers), can help developers positioning problem question the source, can be more timely and efficient positioning problem.

Using the step

Install adb and configure environment variables

If your PC already has an ADB environment installed and configured, skip this step.

For non-developers, download adb tools directly here, unpack them in your directory, and then configure the path of adB. exe in the system environment variable. See here to configure ADB environment variables

Install Cygwin

Cygwin official download address

Depending on whether your computer is 64-bit or 32-bit, click the corresponding download address

After downloading, run setup.exe program and the installation screen will appear. Click “Next” directly, and the dialog box of installation mode will appear, as shown below:

We see three installation modes:

  • Install from the Internet. This mode is suitable for fast network speeds.
  • Download Without Installing, this mode only downloads the Cygwin component package from the Internet, but does not install;
  • Install from Local Directory, this mode corresponds to the second mode above. You can use this mode to Install Cygwin locally when your Cygwin component package has been downloaded locally.

Choose which of the three modes above suits you. Here we choose the first mode and install it directly from the web. Of course, we download the Cygwin components locally so that we can install them again later. Select the path you want to install, go next-next, and select the first option if available

After the installation is complete, open Cygwin Terminal and run

$ cygcheck -c cygwin
Cygwin Package Information
Package              Version        Status
cygwin               3.1.4-1        OK
Copy the code

It prints out the current version and running status of Cygwin. If status is OK, Cygwin is running properly

How do I filter logs?

First prepare a data cable, connect your mobile phone, open Cygwin Terminal, and follow the following steps:

Obtaining device ID

Adb Devices Gets the device idCopy the code
  • The effect

The above Q5S0219527008077 is your device identifier. If it is displayed, it means that your mobile phone is properly connected. If there are multiple devices, it will be listed


If only this device is connected to your PC, pass the following filtering logs directly:

None Example Clear previous logs

Adb logcat -c adb logcat -c adb logcat -c adb logcat -c adb logcat -c adb logcat -cCopy the code

Obtaining all Logs

adb logcat
Copy the code
  • The effect

This will fetch all the logs printed by the phone, but in most cases we will need to filter logs for specific keywords.

Note: after executing the logcat command, the log information will continue to be obtained. If you need to stop printing, pressctrl+c, the same as follows.


Filter logs for a single keyword

Adb logcat | grep "EXE_TAG" -- color / / filter EXE_TAG keyword log, color identification and keywordsCopy the code
  • Effect:

Filter logs with multiple keywords

Log/filter/multiple keywords and keyword color logo / / here is the filter with wyj or EXE_TAG keywords log / / multiple keywords, in turn, in the back to add 1 \ | the \ | keyword keyword 2, adb logcat | grep "wyj \ | EXE_TAG" -- colorCopy the code
  • Effect:

Filtering error logs

Adb logcat *:E (case insensitive) // Filter all error logs But generally focus on e level) the adb logcat * : e | grep "com. Xmexe. Exe"/filter/com. Xmexe. Exe package under the error log (generally focus on this)Copy the code
  • The effect


Saves logs in the specified directory

The adb logcat * : E > c: / error001. TXT / / to save all the error log to the c: / error001 TXT adb logcat * : E | grep "com. Xmexe. Exe" - > error009. TXT // Save error logs from com.xmexe.exe to error009.txtCopy the code

ctrl+c

Similarly, the following command outputs logs for the specified keyword to a file

adb logcat | grep "wyj\|EXE_TAG" >c:/exe002.TXT
Copy the code

Other Common instructions

Adb shell PM list packages adb shell PM list packages Adb shell PM list package-3 adb shell PM list package-3 Shell PM list package-s adb shell PM list package-3Copy the code

For more ADB instructions, see ADB Advanced knowledge. How to filter only viewing a specific app log