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


当前回答

尝试:Window -> Preferences -> Android -> LogCat。修改字段“如果…显示logcat视图”的值为“VERBOSE”。它帮助了我。

其他回答

为了访问日志,首先需要安装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进行过滤。

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

如果你正在使用Android Studio,你可以选择你想要接收日志的进程。 这是截图。

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

对于mac:

adb logcat | grep "MyUniqueString" 

Windows (powershell):

adb logcat | Select-String "MyUniqueString"

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

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