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


当前回答

adb logcat -e "appname" 

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

其他回答

这是Gavriel的applog.sh的另一个变体,支持多个设备和多个进程的应用程序:

#!/bin/sh
PKG=$1
shift

APPIDS=`adb $@ shell ps | awk -v PKG="$PKG" '
    (NR == 1){appcolumn=2; for (i=1; i<=NF; i++) if ($i=="PID") {appcolumn=i}}
    index($0,PKG){print $(appcolumn)}' | paste -d \| -s`

echo "PID's: $APPIDS"
adb $@ logcat -v color | awk  "(\$3 ~ /$APPIDS/){print \$0}"

使用方法:applog.sh com.example.my.package [-s <特定设备>]

为您的日志命名。我叫我的“娃娃儿”。

在Android Studio中,进入Android->编辑过滤器配置

然后输入给日志的名称。对我来说,它叫“娃娃儿”。下面是一些可以使用的过滤器类型的示例。您可以通过系统进行过滤。,系统。err,日志或包名:

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

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