在Android中按PID或应用程序包过滤日志消息 [英] Filter log messages by PID or application package in Android

查看:76
本文介绍了在Android中按PID或应用程序包过滤日志消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我了解要过滤Android日志消息,我们可以使用

  adb logcat ActivityManager:I MyApp:D *:S 

但是,在我的应用程序中,我对不同的活动使用了不同的 TAGS ,我只想过滤该应用程序的所有日志.最好的方法是什么?

我是否需要在命令中指定 all 个标记?

还是在整个应用程序中使用通用标签,唯一的替代方法是?

在Eclipse中查看日志消息时,我注意到有一个名为 PID 的列和另一个名为 Application (包含应用程序包的名称)的列,它们都是(显然)针对给定应用程序的不同 Tag 相同.这表明应该不仅可以通过Tag进行过滤,而且还可以通过pid/package进行过滤.

解决方案

我使用以下通用TAG格式.

例如,对于 Activity ,我定义了一个基本的 Activity 类...

 公共类MyCompanyActivity扩展了活动{受保护的最终字符串TAG = this.getClass().getName();...} 

我创建的

所有 Activity 扩展了 Activity 的示例.

 公共类FishActivity扩展了MyCompanyActivity {...} 

结果是, FishActivity 将具有一个 TAG ,即...

  com.mycompany.myapp.FishActivity 

我接下来要做的就是过滤 com.mycompany.myapp

上的logcat

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.

解决方案

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

这篇关于在Android中按PID或应用程序包过滤日志消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆