Creating Custom Log Filters

Every Android log statement includes a tag. These tags can be used with filters defined in LogCat. To add a new filter, click the green plus sign button in the LogCat pane. Name the filter—perhaps using the tag name—and fill in the tag you want to use. Now there is another tab in LogCat that will show messages that contain this tag. In addition, you can create filters that display items by severity level.

Android convention has largely settled on creating tags based on the name of the class. You see this frequently in the code provided with this book. Note that we create a constant in each class with the same variable name to simplify each logging call. Here's an example:

public static final String DEBUG_TAG = "MyClassName";

This convention isn't a requirement, though. Tags could be organized around specific tasks that span many activities or could use any other logical organization that works for your needs.

0 0

Post a comment