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


当前回答

从Android 7.0开始,logcat有——pid过滤选项,pidof命令可用,将com.example.app替换为您的包名。 (ubuntu终端/ Android 7.0起)

adb logcat --pid=`adb shell pidof -s com.example.app`

or

adb logcat --pid=$(adb shell pidof -s com.example.app)

有关pidof命令的更多信息: https://stackoverflow.com/a/15622698/7651532

其他回答

ADT v15 for Eclipse允许您指定应用程序名称(实际上是androidmanifest.xml中的包值)。

我喜欢通过应用程序进行过滤,但新的logcat在自动滚动方面有一个bug。当您向上滚动一点以查看以前的日志时,它会在几秒钟内自动滚动回底部。在日志中向上滚动1/2的位置似乎可以防止它跳回底部,但这通常是无用的。

编辑:我试着从命令行指定一个应用程序过滤器——但运气不好。如果有人解决了这个问题或者如何停止自动滚动,请告诉我。

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

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:致命。 在发现错误只是在你写的源代码,而不是其他相关的模块

添加过滤器

指定名称

选择你的过滤器。

除了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%