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?
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).
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.
精彩评论