In previous topic we show how to debug android applications using logcat. But, Logcat shows many messages and its really get difficult to check the messages which we have printed from those messages.
Every Android log message has a tag and 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)
Ideally, we should create one private static final String TAG for each class created in project workspace. And write the log message like below:
private static final String TAG="SelfHeal51"; Log.i(TAG, "Height:270");
1) In the logcat screen, there is Create filter button on top right.
2) Write the tag name which you want to filter. In this case, we will filter all the messages with TAG SelfHeal51.
In by Log Tag, we entered, SelfHeal51 and we name the filter as Test. See the screenshot below:
3) Check the filtered Log message
Check in following screenshot, new tab is added in Logcat screen for newly created filter named “Test” in step 2. Here it shows only the messages with TAG SelfHeal51.
We can filter the logcat by the TAG by creating TAG for each
class in our project workspace. It will be then very easy to detect the errors in the project.