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


当前回答

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

其他回答

我写了一个shell脚本,通过包名过滤logcat,我认为这比使用更可靠

ps | grep com.example.package | cut -c10-15

它使用/proc/$pid/cmdline找到实际的pid,然后在logcat上执行grep

https://gist.github.com/kevinxucs/7340e1b1dd2239a2b04a

在linux中,这对我来说是有效的:

adb logcat | grep `adb shell ps | grep your.package | awk '{print $2}'`
adb logcat -e "appname" 

这工作时,过滤行只有一个应用程序。

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

使用-s !

你应该使用你自己的标签,看看: http://developer.android.com/reference/android/util/Log.html 喜欢的。 日志。d(“AlexeysActivity”,“你想要记录什么”); 然后当你想读取日志时使用> adb logcat -s AlexeysActivity 过滤掉所有不使用相同标签的内容。