Filter log messages by PID or application package in Android

六月ゝ 毕业季﹏ 提交于 2021-02-18 11:37:25

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/9658253/filter-log-messages-by-pid-or-application-package-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!