Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Filter log messages by PID or application package in Android

I understand that to filter Android log messages we can use something like

adb logcat ActivityManager:I MyApp:D *:S

But, in my application, I'm using different TAGS for different activities and I want to filter all the logs of this application only. What's the best way to do it?

Do I need to specify all the tags in the command?

Or using a common tag across the application, the only other alternative?

While looking at log messages in Eclipse, I notice that there is a column named PID and another named Application (contains name of app package) both of which are (obviously) same for different Tag for a given application. That suggests that it should be possible to filter not just by Tag but by pid/package as well.

like image 823
Atul Goyal Avatar asked Mar 11 '12 19:03

Atul Goyal


People also ask

How do I find application logs on Android?

Navigate to device settings and enable Developer Options (see section for ADB logs) Navigate to Developer Options and tap on Take/Submit Bug Report. Select Full Report when prompted to get the full device info along with the logs.

What is PID in Logcat?

pid = process ID. uid = user ID of the application that owns that process.

Which method is used to generate log messages?

The Logcat window in Android Studio displays system messages, such as when a garbage collection occurs, and messages that you added to your app with the Log class. It displays messages in real time and keeps a history so you can view older messages.


1 Answers

I use a common TAG format as follows.

For Activities for example, I have defined a base Activity class...

public class MyCompanyActivity extends Activity {
    protected final String TAG = this.getClass().getName();
    ...
}

All Activities I create extend that Activity, example.

public class FishActivity extends MyCompanyActivity {
    ...
}

The result is that FishActivity will have a TAG which is...

com.mycompany.myapp.FishActivity

All I then need to do is filter the logcat on com.mycompany.myapp

like image 71
Squonk Avatar answered Oct 20 '22 07:10

Squonk