我观察到,当我使用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%

其他回答

这已经为我工作在git bash:

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

我不确定是否有一种方法只能看到关于你的应用程序的系统消息,但你可以基于字符串进行过滤。如果在程序中执行日志,则可以只包含某个惟一的关键字,并基于该关键字进行筛选。

这显然是一个针对从开发人员设备外部使用Logcat的问题,但是如果你想在设备上(以编程方式)显示Logcat输出,你只需要这个:

Runtime.getRuntime().exec("logcat " + android.os.Process.myPid() + " *:D");

末尾的*:D会过滤掉Debug日志级别以下的所有消息,但您可以省略它。

直接输出到,比如说,一个TextView,请看这里的例子。

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

使用-s !

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