过滤 LogCat 以仅获取来自 Android 中的“我的应用程序”的消息?

发布于 2024-11-26 14:56:24 字数 102 浏览 3 评论 0原文

我观察到,当我将 Logcat 与 Eclipse 和 ADT for Android 一起使用时,我也会从许多其他应用程序收到消息。有没有办法过滤此内容并仅显示来自我自己的应用程序的消息。

I observed that when i use Logcat with Eclipse with ADT for Android, I get messages from many other applications as well. Is there a way to filter this and show only messages from my own application only.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(30

赢得她心 2024-12-03 14:56:24

注意:以下答案已有 10 多年历史。这可能不再是最好的答案。我目前实现此目的的首选方法是 https://stackoverflow.com/a/76551835/1292598

Linux OS X

使用 ps/grep/cut 获取 PID,然后使用 grep 获取具有该 PID 的 logcat 条目。这是我使用的命令:(

adb logcat | grep -F "`adb shell ps | grep com.asanayoga.asanarebel | tr -s [:space:] ' ' | cut -d' ' -f2`"

您可以进一步改进正则表达式,以避免包含相同数字的不相关日志行的理论问题,但这对我来说从来不是问题)

这在匹配多个进程时也适用。

Windows

在 Windows 上,要获取完整日志,您可以执行以下操作:

adb logcat | findstr com.example.package

Logcat 日志具有获取信息的级别:

V — 详细、D — 调试、I — 信息、W — 警告、E — 错误、F — 致命、S — Silent

因此,要仅获取与应用程序相关的错误日志,您可以按如下方式更新上述命令:

adb logcat *:E | findstr com.example.package

Note: The following answer is over 10 years old. It's probably not the best answer anymore. My current preferred way of accomplishing this is https://stackoverflow.com/a/76551835/1292598

Linux and OS X

Use ps/grep/cut to grab the PID, then grep for logcat entries with that PID. Here's the command I use:

adb logcat | grep -F "`adb shell ps | grep com.asanayoga.asanarebel | tr -s [:space:] ' ' | cut -d' ' -f2`"

(You could improve the regex further to avoid the theoretical problem of unrelated log lines containing the same number, but it's never been an issue for me)

This also works when matching multiple processes.

Windows

On Windows, to get full logs, you can do:

adb logcat | findstr com.example.package

Logcat logs has got levels at which to get info:

V — Verbose, D — Debug, I — Info, W — Warning, E — Error, F — Fatal, S — Silent

So to get only error logs related to the app, you can update the above command as follows:

adb logcat *:E | findstr com.example.package
刘备忘录 2024-12-03 14:56:24

包名称保证是唯一的,因此您可以使用 Log 函数并将标签作为包名称,然后按包名称进行过滤

注意:自构建起工具 21.0.3 将不再起作用,因为标签限制为 23 个字符或更少。

Log.("", "message");代码>

adb -d logcat <你的包名称>:<日志级别> *:S

-d 表示实际设备,-e 表示模拟器。如果运行的模拟器超过 1 个,您可以使用 -s emulator-(例如 -s emulator-5558

示例:adb -d logcat com.example.example:I *:S

或者,如果您使用 System.out.print 将消息发送到日志,则可以使用 adb -d logcat System.out.println() 。输出:我*:S 仅显示对 System.out 的调用。

您可以在此处找到所有日志级别和更多信息:https://developer.android.com/studio/命令行/logcat.html

http://developer.android.com/reference/android /util/Log.html

编辑:看起来像我有点操之过急,才意识到您问的是 Eclipse 中的 logcat。我上面发布的内容是通过 adb 从命令行使用 logcat。我不确定相同的过滤器是否转移到 Eclipse 中。

Package names are guaranteed to be unique so you can use the Log function with the tag as your package name and then filter by package name:

NOTE: As of Build Tools 21.0.3 this will no longer work as TAGS are restricted to 23 characters or less.

Log.<log level>("<your package name>", "message");

adb -d logcat <your package name>:<log level> *:S

-d denotes an actual device and -e denotes an emulator. If there's more than 1 emulator running you can use -s emulator-<emulator number> (eg, -s emulator-5558)

Example: adb -d logcat com.example.example:I *:S

Or if you are using System.out.print to send messages to the log you can use adb -d logcat System.out:I *:S to show only calls to System.out.

You can find all the log levels and more info here: https://developer.android.com/studio/command-line/logcat.html

http://developer.android.com/reference/android/util/Log.html

EDIT: Looks like I jumped the gun a little and just realized you were asking about logcat in Eclipse. What I posted above is for using logcat through adb from the command line. I'm not sure if the same filters transfer over into Eclipse.

空城仅有旧梦在 2024-12-03 14:56:24

从Android 7.0开始,logcat有--pid过滤选项,并且可以使用pidof命令,将com.example.app替换为您的包名称。
(ubuntu 终端/自 Android 7.0 起)

adb logcat --pid=`adb shell pidof -s com.example.app`

adb logcat --pid=$(adb shell pidof -s com.example.app)

有关 pidof 命令的更多信息:
https://stackoverflow.com/a/15622698/7651532

Since Android 7.0, logcat has --pid filter option, and pidof command is available, replace com.example.app to your package name.
(ubuntu terminal / Since Android 7.0)

adb logcat --pid=`adb shell pidof -s com.example.app`

or

adb logcat --pid=$(adb shell pidof -s com.example.app)

For more info about pidof command:
https://stackoverflow.com/a/15622698/7651532

故人爱我别走 2024-12-03 14:56:24

这对我来说适用于 USB 调试:

解决方案是直接通过 shell 使用设备自己的 logcat

  1. 连接设备并使用:

    adb shell

  2. 设置 shell 后使用 logcat:

    <代码>logcat | grep com.yourapp.packagename

This works for me with USB debugging:

The solution was to use your device's own logcat directly via shell.

  1. Connect the device and use:

    adb shell

  2. Use logcat after the shell is set up:

    logcat | grep com.yourapp.packagename

各自安好 2024-12-03 14:56:24

添加过滤器

添加过滤器

指定名称

在此处输入图像描述

选择您的过滤器。

在此处输入图像描述

Add filter

Add filter

Specify names

enter image description here

Choose your filter.

enter image description here

败给现实 2024-12-03 14:56:24
adb logcat -e "package-name" 

当仅过滤一个应用程序的行时,此功能非常有效。

adb logcat -e "package-name" 

This works prefectly when filtering rows for one app only.

陈甜 2024-12-03 14:56:24

对我来说,这适用于 mac Terminal
进入 adb 所在的文件夹,然后在终端中输入以下命令

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

,这里它将过滤 MyTAGAndroidRuntime 的所有日志

For me this works in mac Terminal
Got to the folder where you have adb then type below command in terminal

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

Here it will filter all logs of MyTAG and AndroidRuntime

愿与i 2024-12-03 14:56:24

对于可调试应用程序,我建议

adb shell run-as my.package.name logcat

run-as 不适用于不可调试应用程序,因此对于那些我使用 --uid 标志的应用程序。不幸的是,没有 uidof,所以我需要从 pm 中提取它。下面是一个用于执行此操作的小 sh 脚本:

function logcat {
  pkg="$1"
  shift
  if [ -z "$pkg" ]; then
    >&2 echo 'Usage: logcat pkg ...'
    return 1
  fi

  uid="$(adb shell pm list package -U $pkg | sed 's/.*uid://')"
  if [ -z "$uid" ]; then
    >&2 echo "pkg '$pkg' not found"
    return 1
  fi

  adb logcat --uid="$uid" "$@"
}

用法是 logcat my.package.name。它像普通的 logcat 一样接受额外的参数。

与基于 --pidof 的解决方案相比,我更喜欢这个(请参阅https://stackoverflow.com/a/48004086 /1292598),因为这需要您在每次重新启动进程时重新运行该命令。

For a debuggable application, I suggest

adb shell run-as my.package.name logcat

run-as doesn't work for non-debuggable applications, so for those I use the --uid flag. Unfortunately there isn't a uidof, so I need to extract it from pm. Here's a small sh script to do that:

function logcat {
  pkg="$1"
  shift
  if [ -z "$pkg" ]; then
    >&2 echo 'Usage: logcat pkg ...'
    return 1
  fi

  uid="$(adb shell pm list package -U $pkg | sed 's/.*uid://')"
  if [ -z "$uid" ]; then
    >&2 echo "pkg '$pkg' not found"
    return 1
  fi

  adb logcat --uid="$uid" "$@"
}

Usage is logcat my.package.name. It accepts additional arguments like normal logcat.

I prefer this to the --pidof based solution (see https://stackoverflow.com/a/48004086/1292598) since that requires you to re-run the command each time the process is restarted.

抽个烟儿 2024-12-03 14:56:24

5 月 17 日更新

几年过去了,事情已经发生了变化。并且 Eclipse 不再受到官方支持。所以这里还有另外两种最新的方法:

1. Android Studio

在此处输入图像描述
Android Monitor 工具箱中,您可以按可调试进程过滤 logcat。通常,当您开发应用程序时,它是一个可调试的过程。每隔一段时间我就会遇到这个问题,然后执行以下操作:

  1. 工具 -> Android -> 启用 ADB 集成
    如果它已经启用,则将其关闭,然后重新打开

  2. 拔下并重新插入您的移动设备。

还有通过正则表达式和调试级别

2 进行过滤的选项。 logcat-color

这是一个如果您想使用基于终端的解决方案,那么在 adb logcat 之上有一个不错的 python 包装器。它的好处是您可以保存多个配置并简单地重复使用它们。按标签过滤是相当可靠的。您还可以按package进行过滤,以仅查看一个或多个应用程序的日志,但您可以在启动应用程序之前启动logcat-color

旧答案:

看来我不能评论以前的答案,所以我会发布一个新的。
这是对 Tom Mulcahy 的回答的评论,它显示了命令应如何更改才能在大多数设备上工作,因为 adb shell ps PID 列是可变的。

注意:以下命令适用于您连接了许多设备的情况。因此需要设备ID。否则,您可以简单地省略括号“[”、“]”

1。要查找 pid 列,请键入:

adb [-s DEVICE_ID] shell ps | head -n 1

现在记住 PID 的列号。编号从1开始。

2.然后输入以下内容:

adb [-s DEVICE_ID] logcat | grep $(adb [-s DEVICE_ID] shell ps \
| grep "com.example" | awk -F" " ' {print $PUT_COLUMN_HERE}')

只需将您记住的列放入 PUT_COLUMN_HERE 中,例如 $5

警告

每次重新运行应用程序时,您都必须重新运行第二个命令,因为应用程序从操作系统获取新的 PID。

Update May 17

It's been a few years, and thing have changed. And Eclipse is no longer officially supported. So here's two more up-to-date approaches:

1. Android Studio

enter image description here
In the Android monitor toolbox, you can filter logcat per debuggable process. Normally, when you develop an application it is a debuggable process. Every once in a while I am having issues with this, and a do the following:

  1. Tools -> Android -> Enable ADB Integration.

    If it was already enabled, then toggle it off, and then back on

  2. Unplug and replug your mobile device.

There are also options to filter via regex and the debug level

2. logcat-color

This is a nice python wrapper on top of adb logcat if you want to use a terminal based solution. The good thing about it is that you can save multiple configurations and simply reuse them. Filtering by tags is quite reliable. You can also filter by package to see logs of one or more apps only, but you start logcat-color right before launching your app.

Old Answer:

It seems that I can't comment to previous answers, so I will post a new one.
This is a comment to Tom Mulcahy's answer, that shows how the command should change so as to work on most devices, since adb shell ps PID column is variable.

NOTE: The command below works for the cases where you have connected many devices. So device id is needed. Otherwise, you can simply omit the brackets '[', ']'

1. To find out the column of pid, type:

adb [-s DEVICE_ID] shell ps | head -n 1

Now memorise the column number for the PID. Numbering starts from 1.

2. Then type the following:

adb [-s DEVICE_ID] logcat | grep $(adb [-s DEVICE_ID] shell ps \
| grep "com.example" | awk -F" " ' {print $PUT_COLUMN_HERE}')

Simply put the column you memorised in PUT_COLUMN_HERE, e.g. $5

Caveat

Each time you re-run your application, you have to re-run the 2nd command, because the application gets a new PID from the OS.

耶耶耶 2024-12-03 14:56:24

Ubuntu : adb logcat -b all -v color --pid=`adb shell pidof -s com.packagename` 带有应用程序的颜色和连续日志

Ubuntu : adb logcat -b all -v color --pid=`adb shell pidof -s com.packagename` With color and continous log of app

夜深人未静 2024-12-03 14:56:24

这在 git bash 中对我有用:

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

This has been working for me in git bash:

$ pid=$(adb shell ps | grep <package name> | cut -c11-15) ; adb logcat | grep $pid
明月松间行 2024-12-03 14:56:24

然后将其放入 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 '^


applog.sh com.example.my.package

\ | grep " ${APPPID}:"


applog.sh com.example.my.package

put this to 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 '^

then:
applog.sh com.example.my.package

\ | grep " ${APPPID}:"

then:
applog.sh com.example.my.package

弥繁 2024-12-03 14:56:24

使用 Windows 命令提示符:adb logcat -d | findstr.

*这是jj_首先提到的,但我花了很长时间才在评论中找到它......

Using Windows command prompt: adb logcat -d | findstr <package>.

*This was first mentioned by jj_, but it took me ages to find it in the comments...

逐鹿 2024-12-03 14:56:24

为了访问 logcats,您首先需要安装 ADB 命令行工具。 ADB命令行工具是android studio平台工具的一部分,可以从此处。之后,您需要为 adb 工具设置路径/环境变量。现在,如果您使用的是 macbook,您可以从 eclipse 终端/intellij 终端或 mac 终端访问 logcat。

adb logcat :获取整个 logcat。

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

adb logcat pid= :获取特定于您的应用的 logcat。

adb logcat pid=|grep 'sometext' :根据某些文本过滤 logcat。

有关过滤 logcat 的更多信息,请阅读

In order to access the logcats you first need to install ADB command-line tool. ADB command-line tool is a part of android studio platform tools and can be downloaded from here. After this, you need to set the path/environment variable for adb tools. Now you can access logcat from eclipse terminal/ intellij terminal or mac terminal in case you are using a macbook.

adb logcat : To get entire logcat.

adb shell pidof 'com.example.debug' : To get the process id of your app.

adb logcat pid=<pid> : To get logcat specific to your app.

adb logcat pid=<pid>|grep 'sometext' : To filter logcat on basis of some text.

For more info about filtering logcats read this.

酒绊 2024-12-03 14:56:24

如果您使用的是 Android Studio,您可以选择要从中接收 logcat 的进程。
这是屏幕截图。

在此处输入图像描述

If you are using Android Studio you can select the process from which you want to receive logcats.
Here is the screenshot.

enter image description here

猫弦 2024-12-03 14:56:24

我编写了一个shell脚本,用于按包名称过滤logcat,我认为这比使用它更可靠

ps | grep com.example.package | cut -c10-15

它使用/proc/$pid/cmdline来找出实际的pid,然后在logcat

https://gist.github.com/kevinxucs/7340e1b1dd2239a2b04a

I wrote a shell script for filtering logcat by package name, which I think is more reliable than using

ps | grep com.example.package | cut -c10-15

It uses /proc/$pid/cmdline to find out the actual pid, then do a grep on logcat

https://gist.github.com/kevinxucs/7340e1b1dd2239a2b04a

壹場煙雨 2024-12-03 14:56:24

使用-s

你应该使用你自己的标签,看看:
http://developer.android.com/reference/android/util/Log.html

喜欢。

Log.d("AlexeysActivity","你要记录的内容");

然后当你想阅读日志时使用>

adb logcat -s AlexeysActivity

这会过滤掉所有不使用相同标签的内容。

来源

Use -s !

You should use your own tag, look at:
http://developer.android.com/reference/android/util/Log.html

Like.

Log.d("AlexeysActivity","what you want to log");

And then when you want to read the log use>

adb logcat -s AlexeysActivity

That filters out everything that doesn't use the same tag.

Source

2024-12-03 14:56:24

LogCat 应用程序消息

作为一种变体,您可以使用第三方脚本 PID Cat杰克·沃顿。该脚本有两个主要优点:

  • 显示特定应用程序包中进程的日志条目
  • color logcat

来自文档:

在应用程序开发过程中,您通常只想显示来自应用程序的日志消息。不幸的是,由于每次部署到手机时进程 ID 都会发生变化,因此 grep 找到正确的内容就成了一个挑战。

该脚本通过按应用程序包过滤来解决该问题。

输出看起来像
输入图片此处描述

LogCat Application messages

As a variant you can use third party script PID Cat by Jake Wharton. This script has two major advantages:

  • shows log entries for processes from a specific application package
  • color logcat

From documentation:

During application development you often want to only display log messages coming from your app. Unfortunately, because the process ID changes every time you deploy to the phone it becomes a challenge to grep for the right thing.

This script solves that problem by filtering by application package.

An output looks like
enter image description here

若沐 2024-12-03 14:56:24

ADT v15 for Eclipse 允许您指定应用程序名称(实际上是 androidmanifest.xml 中的包值)。

我喜欢能够按应用程序进行过滤,但是新的 logcat 在自动滚动方面有一个错误。当您向上滚动一点查看以前的日志时,它会在几秒钟内自动滚动回底部。看起来向上滚动日志的 1/2 确实可以防止它跳回底部,但这通常是无用的。

编辑:我尝试从命令行指定应用程序过滤器 - 但没有成功。如果有人弄清楚这一点或如何停止自动滚动,请告诉我。

ADT v15 for Eclipse let you specify an application name (which is actually the package value in your androidmanifest.xml).

I love being able to filter by app, but the new logcat has a bug with the autoscroll. When you scroll up a little to look at previous logs, it automatically scrolls back to the bottom in a couple seconds. It seems scrolling 1/2 way up the log does keep it from jumping back to the bottom, but that's often useless.

EDIT: I tried specifying an app filter from the command-line -- but no luck. If someone figures this out OR how to stop the autoscroll, please let me know.

傾城如夢未必闌珊 2024-12-03 14:56:24

我通常会在日志消息中添加一些内容以使其与众不同。或者例如统一应用程序,您可以使用“Unity”作为匹配字符串。

对于 Mac:

adb logcat | grep "MyUniqueString" 

对于 Windows(powershell):

adb logcat | Select-String "MyUniqueString"

I am usually adding something in the log messages to make it distinct. Or for example unity app you can use "Unity" as matching string.

For mac :

adb logcat | grep "MyUniqueString" 

for Windows (powershell ):

adb logcat | Select-String "MyUniqueString"
旧时光的容颜 2024-12-03 14:56:24

我有不同的方法,你可以尝试访问本地设备的外壳。

adb shell

然后是

logcat | grep com.package.name

这会打印所有包含该包的内容。

或者,您可以尝试 flutter log --verbose

I have different approach, you can try access to local device's shell.

adb shell

and then follow by

logcat | grep com.package.name

This print all containing that package.

Alternatively, You can try flutter logs --verbose

埖埖迣鎅 2024-12-03 14:56:24

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

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

Another way of getting logs of exact package name when you are inside the shell:

logcat --pid $(ps -ef | grep -E "com.example.app\
quot; | awk '{print $2}') 
您的好友蓝忘机已上羡 2024-12-03 14:56:24

在 Windows 10 上,使用 Ionic,对我来说最有效的是将“findstr”与所有应用程序消息生成的“INFO:CONSOLE”结合起来。
所以,我在命令行中的命令是:

adb logcat | findstr INFO:CONSOLE

On Windows 10, using Ionic, what worked great to me was combine 'findstr' with the "INFO:CONSOLE" generated by all App messages.
So, my command in command line is:

adb logcat | findstr INFO:CONSOLE
み零 2024-12-03 14:56:24

我不确定是否有办法只查看有关您的应用程序的系统消息,但您可以根据字符串进行过滤。如果您在程序中进行日志记录,则可以仅包含某个唯一的关键字,并根据该单词进行过滤。

I'm not sure there's a way to only see system messages regarding your app, but you can filter based on a string. If you're doing a log within the program, you can just include a certain unique keyword, and filter based on that word.

回心转意 2024-12-03 14:56:24

尝试:窗口 ->首选项->安卓->日志目录。将“如果...则显示 logcat 视图”字段的值更改为“VERBOSE”。它帮助了我。

Try: Window -> Preferences -> Android -> LogCat. Change field "Show logcat view if ..." the value "VERBOSE". It helped me.

孤星 2024-12-03 14:56:24

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

If you are using Eclipse, press the green + sign in the logCat window below and put your package name (com.example.yourappname) in the by Application Name box. Also, choose any name comfortable to you in Filter Name box and click ok. You will see only messages related to your application when the filter you just added is chosen from the left pane in the logCat.

只有一腔孤勇 2024-12-03 14:56:24

为您的日志命名。我称我的为“wawa”。

在此处输入图像描述

在 Android Studio 中,转到 Android->;编辑过滤器配置

在此处输入图像描述

然后输入您为日志指定的名称。就我而言,它被称为“wawa”。以下是您可以使用的过滤器类型的一些示例。您可以按 System.out、System.err、日志或包名称进行过滤:

在此处输入图像描述
在此处输入图像描述
在此处输入图像描述

Give your log a name. I called mine "wawa".

enter image description here

In Android Studio, go to Android-> Edit Filter Configurations

enter image description here

Then type in the name you gave the logs. In my case, it's called "wawa". Here are some examples of the types of filters you can do. You can filter by System.out, System.err, Logs, or package names:

enter image description here
enter image description here
enter image description here

兔姬 2024-12-03 14:56:24

这可能是最简单的解决方案。

在 Tom Mulcahy 的解决方案之上,您可以进一步简化它,如下所示:

alias logcat="adb logcat | grep `adb shell ps | egrep '\bcom.your.package.name\b' | cut -c10-15`"

使用与普通别名一样简单。只需在 shell 中输入命令即可:

logcat

别名设置非常方便。假设您只关心主进程,正则表达式使其对于多进程应用程序来说非常强大。

当然,您可以根据需要为每个进程设置更多别名。或者使用hegazy 的解决方案。 :)

另外,如果要设置日志记录级别,则是

alias logcat-w="adb logcat *:W | grep `adb shell ps | egrep '\bcom.your.package.name\b' | cut -c10-15`"

This is probably the simplest solution.

On top of a solution from Tom Mulcahy, you can further simplify it like below:

alias logcat="adb logcat | grep `adb shell ps | egrep '\bcom.your.package.name\b' | cut -c10-15`"

Usage is easy as normal alias. Just type the command in your shell:

logcat

The alias setup makes it handy. And the regex makes it robust for multi-process apps, assuming you care about the main process only.

Of coz you can set more aliases for each process as you please. Or use hegazy's solution. :)

In addition, if you want to set logging levels, it is

alias logcat-w="adb logcat *:W | grep `adb shell ps | egrep '\bcom.your.package.name\b' | cut -c10-15`"
—━☆沉默づ 2024-12-03 14:56:24

您可以使用以下命令来获取应用程序包的详细日志

adb logcat com.example.myapp:V *:S

另外,如果您已经推出了应用程序并且想要从已发布的应用程序中获取错误日志,则可以使用以下命令。

adb logcat AndroidRuntime:E *:S

You can use below command to fetch verbose logs for your application package

adb logcat com.example.myapp:V *:S

Also if you have rolled out your app and you want to fetch error logs from released app, you can use below command.

adb logcat AndroidRuntime:E *:S

暖阳 2024-12-03 14:56:24

我尝试使用 Tom Mulcahy 的答案,但不幸的是它不适用于具有多个进程的应用程序,因此我对其进行编辑以满足我的需求。

#!/bin/bash
if [ "$#" -ne 1 ]; then echo "Illegal number of parameters"; exit 1; fi
echo "Lof for package name: $1"
PROCESSES=`adb shell ps | grep "$1" | cut -c10-15`
NUM_OF_PROCESSES=`echo "$PROCESSES" | wc -l`
if [ $NUM_OF_PROCESSES -eq 0 ]; then echo "The application is not running!"; exit 1; fi
COUNTER=1
for process in $PROCESSES; do
        if [ $COUNTER -eq 1 ]; then GREP_TEXT="("; fi
        GREP_TEXT+=$process
        if [ $COUNTER -eq $NUM_OF_PROCESSES ]; then GREP_TEXT+=")"; else GREP_TEXT+="|"; fi
        let COUNTER=COUNTER+1 
        if [ $COUNTER -gt $NUM_OF_PROCESSES ]; then break; fi  
done
adb logcat | grep -E "$GREP_TEXT"

I tried to use Tom Mulcahy's answer but unfortunately it was not working for applications with multiple processes so I edit it to fit my needs.

#!/bin/bash
if [ "$#" -ne 1 ]; then echo "Illegal number of parameters"; exit 1; fi
echo "Lof for package name: $1"
PROCESSES=`adb shell ps | grep "$1" | cut -c10-15`
NUM_OF_PROCESSES=`echo "$PROCESSES" | wc -l`
if [ $NUM_OF_PROCESSES -eq 0 ]; then echo "The application is not running!"; exit 1; fi
COUNTER=1
for process in $PROCESSES; do
        if [ $COUNTER -eq 1 ]; then GREP_TEXT="("; fi
        GREP_TEXT+=$process
        if [ $COUNTER -eq $NUM_OF_PROCESSES ]; then GREP_TEXT+=")"; else GREP_TEXT+="|"; fi
        let COUNTER=COUNTER+1 
        if [ $COUNTER -gt $NUM_OF_PROCESSES ]; then break; fi  
done
adb logcat | grep -E "$GREP_TEXT"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文