本文介绍了过滤 LogCat 以仅获取来自 Android 中我的应用程序的消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我观察到,当我将 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.

推荐答案

包名保证是唯一的,所以你可以使用 Log 函数将标签作为你的包名,然后按包名过滤:

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:

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

Log.("", "message");

adb -d logcat :*:S

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

-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)

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

或者如果您使用 System.out.print 向日志发送消息,您可以使用 adb -d logcat System.out:I *:S 来显示只调用 System.out.

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.

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

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

看起来我有点过头了,刚刚意识到您在 Eclipse 中询问 logcat.我上面发布的内容是从命令行通过 adb 使用 logcat.我不确定相同的过滤器是否会转移到 Eclipse 中.

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.

这篇关于过滤 LogCat 以仅获取来自 Android 中我的应用程序的消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

查看更多