我观察到,当我使用Logcat Eclipse ADT for Android时,我也从许多其他应用程序获得消息。是否有一种方法来过滤这个,只显示来自我自己的应用程序的消息。


当前回答

Ubuntu: adb logcat -b all -v color——pid= ' adb shell pidof -s com。packagename '与颜色和连续日志的应用程序

其他回答

现在可以输入tag:nameofthetag或app:nameoftheapp来过滤,而不需要在保存的过滤器栏中添加新的过滤器

把这个放到applog.sh

#!/bin/sh
PACKAGE=$1
APPPID=`adb -d shell ps | grep "${PACKAGE}" | cut -c10-15 | sed -e 's/ //g'`
adb -d logcat -v long \
 | tr -d '\r' | sed -e '/^\[.*\]/ {N; s/\n/ /}' | grep -v '^$' \
 | grep " ${APPPID}:"

然后: applog.sh com.example.my.package

Linux和OS X

使用ps/grep/cut获取PID,然后使用grep获取具有该PID的logcat条目。下面是我使用的命令:

adb logcat | grep -F "`adb shell ps | grep com.asanayoga.asanarebel  | tr -s [:space:] ' ' | cut -d' ' -f2`"

(您可以进一步改进正则表达式,以避免不相关的日志行包含相同的数字的理论问题,但这对我来说从来都不是问题)

这在匹配多个进程时也适用。

窗户

在Windows上,你可以这样做:

adb logcat | findstr com.example.package

如果您正在使用Eclipse,请在下面的logCat窗口中按下绿色+号,并将您的包名称(com.example.yourappname)放在按应用程序名称框中。此外,在“筛选器名称”框中选择任何适合您的名称,然后单击“确定”。当从logCat的左窗格中选择刚才添加的筛选器时,您将只看到与应用程序相关的消息。

我通常会在日志消息中添加一些内容以使其与众不同。或者以unity app为例,你可以使用“unity”作为匹配字符串。

对于mac:

adb logcat | grep "MyUniqueString" 

Windows (powershell):

adb logcat | Select-String "MyUniqueString"