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


当前回答

这适用于我的USB调试:

解决方案是通过shell直接使用您的设备自己的logcat。

连接设备并使用: 亚行壳 在shell设置完成后使用logcat: Logcat | grep com.yourapp.packagename

其他回答

添加过滤器

指定名称

选择你的过滤器。

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

对于mac:

adb logcat | grep "MyUniqueString" 

Windows (powershell):

adb logcat | Select-String "MyUniqueString"

Windows命令提示符方式:adb logcat -d | findstr <package>.使用实例

*这是jj_首先提到的,但我花了很长时间才在评论中找到它…

除了Tom Mulcahy的回答,如果你想在Windows的控制台上通过PID进行过滤,你可以创建一个像这样的批处理文件:

@ECHO OFF

:: find the process id of our app (2nd token)
FOR /F "tokens=1-2" %%A IN ('adb shell ps ^| findstr com.example.my.package') DO SET PID=%%B

:: run logcat and filter the output by PID
adb logcat | findstr %PID%

把这个放到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