We can always see the log log content of the program is full of screens in the Android development, and the information that really makes sense to the developer is submerged in the torrent, so that the developers are at a loss and seriously affect the development efficiency. This article describes several methods of filtering adblogcat output in the shell command line. 1, only show the required output (whitelist) The most convenient of course is through the pipeline using grep filtering, so you can use grep strong regular expression matching. Simply match a string in a row, such as myapp:adb Logcat | grep myappadb Logcat | Grep-i MyApp #忽略大小写. ADB Logcat | grep--color=auto-i MyApp #设置匹配字符串颜色. For more settings, see grep Help. The advanced point can be matched using grep's regular expression. For example, the previous example matches the MyApp anywhere in a row, and can be set to match tag only. The default log output is as follows, and the corresponding expression is modified if the output format has been modified. I/cacheservice (665): Preparing diskcache for all thumbnails. You can see that the tag starts with the third character at the beginning of a line and writes the expression according to this: adb logcat | grep "^. MyApp "Depending on this format, you can also set a log that shows only a priority, and then match the first character in the beginning of the line. For example, only the output of the Error level tag MyApp is displayed: adb logcat | grep "^e.myapp" can of course also match multiple, using | Split multiple matching expressions to add escape characters. For example, to match the output of the tag MyApp and myactivity: adb logcat | grep "^. myapp\|^. MyActivity "adb logcat | Grep-e "^. myapp|^. MyActivity "#使用 egrep no need to escape character 2, filter unwanted output (blacklist) or use grep, the usage is the same as above, plus a-v. For example, to filter the output of the tag to MyApp and myactivity: adb logcat | Grep-v "^. myapp\|^. MyActivity "adb logcat | Grep-ve "^. myapp|^. MyActivity "#使用 egrep NoMust escape character 3, display all output of the same process sometimes a program has more than one tag, you need to output the program (the same PID) of all tags; using tag filtering can sometimes leave out some error messages, and the general error message is the same PID as the program. or through grep, the idea is to first find the PID number according to the package name, and then match the PID. Write the shell script as follows, the parameter is the Java package name of the program (such as Com.android.media). #!/bin/bashpackagename=$1adb Logcat | Grep–color=auto $pid 4, from the current start to show the Logcat has a cache, if you only need to view the current start of the log, you need to empty the previous. ADB logcat-c && adb logcat 5, filter log files sometimes need to parse the log file, filter the log file or use grep. For example, the log file is Myapp.log, to match the output of tag MyApp and myactivity, and then output to Newmyapp.log:cat Myapp.log | grep "^. myapp\|^. MyActivity "> Newmyapp.log Windows recommends using notepad++, a free powerful notepad that supports regular expression lookup replacements. You can highlight matches or delete unwanted content. The above technique mainly uses the grep, actually LOGCAT itself also has the filtering function, may filter the log according to the tag, the priority level, specifically please refer to the Android Official document reading and Writing Logs. If you prefer to use the graphical interface, please refer to the logcat inside the using DDMS,DDMS can also be filtered.
Several ways to filter adb logcat output in the shell command line