How to filter logcat by command line?

Asked

Viewed 495 times

6

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

I installed a minimalist version of ADB (only what is necessary for it to work on the command line) and I’m trying to monitor application errors on my phone, to make it easier to read, I export to a text file at the command prompt, using the command below:

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

This command already meets my purpose, but it records everything that occurs on the mobile, and I would like it to be recorded only errors, and if it is possible to filter this, of running applications.

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

1 answer

5


It is possible to filter the output of the logcat for tag and level of priority.

An input in logcat is recorded by calling one of the Log class methods. The called method sets 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 the entries we want to list and priority is the minimum level of priority minimal to be listed. You can use more than one filter expression by separating it by spaces.

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

adb logcat MyActivity:I *:S 

*:S prevents any other tag be listed.

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

  • for linux users can also use pipe, something like $ adb logcat | grep "MyActivity" that funfa blzura

  • That if I am debugging an app in specific, in case I wanted to investigate the apps running on my device, there is no way I know their activities. There’s no way to filter it?

  • For what I saw in the documentation, no. Just by tag and priority level. Also because the application or activity name does not exist in the log. You can ignore the tag using *, for example list all entries with priority level "error" or higher: adb logcat *:E

  • I managed to use the command adb logcat ActivityManager:I *:S >> C:\\Temp\logcat.txt

Browser other questions tagged

You are not signed in. Login or sign up in order to post.