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

前端 未结 2 647
说谎
说谎 2020-12-20 00: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

相关标签:
2条回答
  • 2020-12-20 01:35

    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.

    enter image description here

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

    0 讨论(0)
  • 2020-12-20 01:40

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

    0 讨论(0)
提交回复
热议问题