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


当前回答

添加过滤器

指定名称

选择你的过滤器。

其他回答

这已经为我工作在git bash:

$ pid=$(adb shell ps | grep <package name> | cut -c11-15) ; adb logcat | grep $pid

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

对我来说,这适用于mac终端 找到你有adb的文件夹,然后在终端中键入下面的命令

./adb logcat MyTAG:V AndroidRuntime:E *:S

这里它将过滤MyTAG和AndroidRuntime的所有日志

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

为了访问日志,首先需要安装ADB命令行工具。ADB命令行工具是android studio平台工具的一部分,可以从这里下载。在此之后,需要设置adb工具的path/environment变量。现在您可以从eclipse终端/ intellij终端或mac终端(如果您使用的是macbook)访问logcat。

adb logcat:获取整个logcat。

adb shell pidof 'com.example.debug':获取应用程序的进程id。

adb logcat pid=<pid>:获取特定于应用程序的logcat。

adb logcat pid=<pid>|grep 'sometext':根据某些文本对logcat进行过滤。

有关过滤日志猫的更多信息,请阅读此。