How to filter logcat by command line?

6

I was reading the android documentation and saw that it is possible monitor logcat by command line, without necessarily having the IDE open.

I installed a minimalist version of ADB (only what is needed for it to work on the command line) and I am trying to monitor applications errors on my phone, for easier reading, I export to a text file at the command prompt, using command below:

adb logcat >> C:\Temp\logcat.txt

This command already suits my purpose, but it registers everything that happens on the phone, and I would like to register only errors, and if it is possible to filter this, from running applications.

Is there any way to do one or both of these filters per command line? I'm not sure how to apply the privacy tags in the command line.

    
asked by anonymous 12.02.2017 / 00:12

1 answer

5

You can filter the output of logcat by tag and priority level.

An entry in the logcat is registered by calling one of the methods of the Log class. The called method defines the priority level ( Log.i() , Log.e() , etc), being the tag defined by the string passed to the first parameter:

Log.i("MyActivity","Passei no onCreate");

The filter expression has the format tag:priority , where tag is the tag of the entries we want to list and priority is the minimum minimum priority level > to be listed. You can use more than one filtering expression, separating them by spaces.

The command to list the entries with tag MyActivity and priority level info or higher is:

adb logcat MyActivity:I *:S 

*:S prevents any other tag from being listed.

For more complete information see How to filter the output of the registry in the documentation.

    
12.02.2017 / 12:27