Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
261 views
in Technique[技术] by (71.8m points)

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

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...