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


当前回答

使用-s !

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

其他回答

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

adb logcat -e "appname" 

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

当你在shell内部时,获取确切包名日志的另一种方法:

logcat --pid $(ps -ef | grep -E "com.example.app\$" | awk '{print $2}') 

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