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


当前回答

在Windows 10上,使用Ionic,对我来说最有效的是将“findstr”与所有应用程序消息生成的“INFO:CONSOLE”结合起来。 所以,我在命令行中的命令是:

adb logcat | findstr INFO:CONSOLE

其他回答

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%

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

Windows CMD

例如,如果您的应用程序包名称为:com.nader.chat

cd C:\Users\[your-username]\AppData\Local\Android\Sdk\platform-tools
adb shell logcat *:E | findstr /c:"at com.nader.chat"

:E只是过滤日志中的错误,你可以替换为V:详细(最低优先级),D:调试,I:信息,W:警告,F:致命。 在发现错误只是在你写的源代码,而不是其他相关的模块