Is there any way to view the log messages from our own application in android?

我是研究僧i 提交于 2019-11-28 05:39:58

问题


I have developed an Android application that performs some network activity. Inside the classes I have implemented the log messages like verbose, debug, info, warn and error. But when I open logcat with argument -d its listing the entire log messages from the device. So its difficult to trace the log messages of my application. Is there any way to filter the log messages of my application from the entire logcat output?


回答1:


Every Android log message has a tag and a priority associated with it:

The tag of a log message is a short string indicating the system
component from which the message originates (for example, "View" 
for the view system).

The priority is one of the following character values, ordered 
from lowest to highest priority:

V — Verbose (lowest priority)
D — Debug
I — Info
W — Warning
E — Error
F — Fatal
S — Silent (highest priority, on which nothing is ever printed)

Here's how to do it:

 adb logcat ActivityManager:I MyApp:D *:S

This will make logs with the tag ActivityManager show up if they have an "Info" level priority or above (Warning, Error, Fatal). The same applies to messages with the tag MyApp and a priority of Debug or above. *:S makes all other messages be silent.

Check this out in the documentation: http://developer.android.com/guide/developing/tools/adb.html#logcat

Further tips

  • I suggest you to keep all other logs to Error or Warning level (*:W). Sometimes you get a problem in your application due some system event or third party application and you do want to be notified of these events!

  • You might want to change the output format of logcat. Play around with these settings (information in the same link above)

  • You might want to check out Coloured output for logcat. I've done some modifications to this script to suit better my needs so maybe you could adjust it too. (I tried to send my modifications to the author but he didn't reply).




回答2:


Logcat has a small + button that lets you create a filter. Use the TAG you used in your app and specify it in the filter. That creates a new tab that shows only your apps messages. While you're at it, I recommend creating a filter for the AndroidRuntime tag. All your exceptions get dumped in there and you can find them very easy.

Of course you can filter these messages more by category (verbose, warn, error, ..) by using the buttons in the same bar.



来源:https://stackoverflow.com/questions/7050601/is-there-any-way-to-view-the-log-messages-from-our-own-application-in-android

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!