How to filter adblogcat output

Source: Internet
Author: User
Tags grep regular expression egrep
How to filter adblogcat output this article describes several tips on how to filter adblogcat output in the shell command line. During development, it is often seen that others' logs are filled with the screen as a flood, and useful information is overwhelmed, which affects the mood and efficiency. Below... how to filter adb logcat output this article describes how to filter adb logcat output in shell command line tips. During development, it is often seen that others' logs are filled with the screen as a flood, and useful information is overwhelmed, which affects the mood and efficiency. Below are some filtering methods I know. 1. only display the desired output. the most convenient way to use the white list is to use grep to filter the output in the pipeline. This way, you can use a powerful grep regular expression for matching. Simply match a string in a row, for example, MyApp: adb logcat | grep MyApp adb logcat | grep-I myapp # case-insensitive. Adb logcat | grep -- color = auto-I myapp # sets the matching string color. For more settings, see grep help. For more information, use the regular expression of grep to match. For example, the previous example matches the MyApp in any position in a row and can be set to match only the tag. The default log output is as follows. if the corresponding expression of the output format has been modified, it must also be modified. I/CacheService (665): Preparing DiskCache for all thumbnails. it can be seen that the tag starts with the third character of a line. Based on this, write the expression adb logcat | grep "^ .. myApp "can also be set to display only logs with a certain priority according to this format, and then match the first character of the line. For example, the output that only shows the Error-level tag as MyApp: adb logcat | grep "^ E. of course, MyApp can also match multiple matching expressions. use | to separate multiple matching expressions, an escape character is required. For example, to match the output of the tag MyApp and MyActivity: adb logcat | grep "^ .. myApp \ | ^ .. myActivity "adb logcat | grep-E" ^ .. myApp | ^ .. myActivity "# use egrep without escaping characters 2. filter unnecessary output, blacklist or grep, the usage is also the same as above, add a-v. For example, to filter the output of the tag MyApp and MyActivity: adb logcat | grep-v "^ .. myApp \ | ^ .. myActivity "adb logcat | grep-vE" ^ .. myApp | ^ .. myActivity "# use egrep without escape character 3. display All outputs of the same process. sometimes there are multiple tags in a program. you need to output all the tags of the program (the same PID; when tag-based filtering is used only, some error messages are sometimes missed. Generally, the error information is the same as the PID of the program. Or through grep, the idea is to first find the pid number based on the package name, and then match the pid. The following is a shell script. the parameter is the java package name of the program (such as com. android. media ). View source code print help 1 #! /Bin/bash 2 packageName = $1 3 pid = 'adb shell ps | grep $ packageName | awk' {print $2} ''4 adb logcat | grep -- color = auto $ pid 4. logcat cache is displayed from the current start. if you only need to view the current start log, you need to clear the previous log. Adb logcat-c & adb logcat 5. Filter log files and analyze log files to filter log files 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. in log Windows, we recommend using Notepad ++, a free and powerful Notepad that supports regular expression search and replacement. You can highlight matching content or delete unnecessary content. The above techniques mainly use grep. In fact, logcat also has a filtering function. you can filter Logs by tag and priority. for details, see the official Android documentation Reading and Writing Logs. If you prefer the graphical interface, see Using DDMS. the logcat in DDMS can also be filtered out. Android logcat detailed usage Android log system provides the function of recording and viewing system debugging information. Logs are recorded from various software and system buffers. you can use the logcat command to view and use logs in the buffer zone. using the logcat command, you can use the logcat command to view the content of the system log buffer: [adb] logcat [ ]... [ ]... Please refer to the Listing of logcat Command Options, which has a detailed description of the logcat Command. you can also use the logcat command on your computer or remote adb shell running on the simulator/device, or view the log output on your computer. $ Adb logcat: # logcat filters logs and outputs each output Android log with a tag and its priority. the log Tag is a brief identifier of the original information of the system component. (For example, "View" is used to View system labels ). the priority has the following sets, which are arranged smoothly from low to high: V-Verbose (lowest priority) d-Debug I-Info W-Warning E-Error F-Fatal S-Silent (highest priority, on which nothing is ever printed) when running logcat, you can see the logcat label list and priority in the first two columns. it is marked as follows: / . The following is an example of logcat output. its priority is I, and the label is ActivityManage: I/ActivityManager (585): Starting activity: Intent {action = android. intent. action ...} to enable log output to reflect the management level, you can also use filters to control log output. filters can help you describe the system's tag level. the filter statement depicts the tag in the following format: priority ..., the tag table indicates the label, and the priority indicates the lowest level of the label report. the log priority can be obtained from the above tag. you can write the tag: priority multiple times in the filter. all of these instructions end with a blank space. The following example shows a column that supports all log information, except for those with "ActivityManager" and "Info" or above, and those with "MyApp" and "Debug" or higher priorities. Level. the priority report is tag. adb logcat ActivityManager: I MyApp: D *: S the last element of the expression above *: S, which is to set all the labels as "silent ", all logs only show "View" and "MyApp". Another use of *: S is to ensure that the log output is limited according to the description of the filter, the filter is also output to the log as an item. the following filter statement shows the log information with a priority of warning or higher: adb logcat *: W if you run logcat on your computer, compared to the remote adbshell, you can also enter a parameter for the environment variable ANDROID_LOG_TAGS: to set the default filter export ANDROID_LOG_TAGS = "ActivityManager: I MyApp: D *: S "Note that if the ANDROID_LOG_TAGS filter runs logcat through a remote shell Alternatively, you can use adb shell logcat to run the simulator/device to output logs. control the log output format. log information includes many metadata fields, including tags and priorities. You can modify the log output format to display a specific metadata domain. You can use the-v option to obtain information about formatted output logs. brief-Display priority/tag and PID of originating process (the default format ). process-Display PID only. tag-Display the priority/tag only. thread-Display process: thread and priority/tag only. raw-Display the raw log message, with no other metadata fields. time-Display the date, invocation time, priority/tag, and PID of the originating process. long-Display all metadata fields and separate messages with a blank lines. when logcat is started, you can use the-v option to specify the output format: [adb] logcat [-v ] The following is the log format generated by using the thread: adb logcat-v thread must note that you only have the-v option to specify the output format option. view Available log buffer Android log system has a circular buffer, not all log systems have a default circular buffer. To obtain the log information, you must use the-B option to start logcat. If you want to use the cyclic buffer, you need to check the remaining cyclic buffer period: radio-view the information about the buffer. events-view the event-related buffer. main-view the main log buffer-B option usage: [adb] logcat [-B ] The following example shows how to view the log buffer that contains radio and telephony information: adb logcat-B radio to view stdout and stderr. by default, the Android System has stdout and stderr (System. out and System. err) output to/dev/null. in the process of running Dalvik VM, a system can back up log files. In this case, the system uses stdout and stderr and priority I. this method is used to specify the output path, stop the running simulator/device, and then use setprop to remotely enter the log $ adb shell stop $ adb shell setprop log. redirect-stdio true $ adb shell start system is retained until you disable the simulator/device. you can add/data/local. prop can use the default Logcat command list Option Description-B on the simulator/device Load an available log buffer for viewing, such as event and radio. the default value is main. For details, see Viewing Alternative Log Buffers.-c to clearly view the Log on the screen.-d to output the Log to the screen.-f Specify By default, it is the specified log buffer output by stdout.-g, and exits after the output.-n Set the maximum number of logs . The default value is 4, which must be used with the-r option. -R Each When the log is output, the default value is 16. use.-s with the-f option to set the default filtering level to silent.-v. Set the Log input Format. the default Format is the brief Format. for more supported formats, see Controlling Log Output Format.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.