7

I understand that to filter Android log messages we can use something like

adb logcat ActivityManager:I MyApp:D *:S

But, in my application, I'm using different TAGS for different activities and I want to filter all the logs of this application only. What's the best way to do it?

Do I need to specify all the tags in the command?

Or using a common tag across the application, the only other alternative?

While looking at log messages in Eclipse, I notice that there is a column named PID and another named Application (contains name of app package) both of which are (obviously) same for different Tag for a given application. That suggests that it should be possible to filter not just by Tag but by pid/package as well.

Atul Goyal
  • 3,511
  • 5
  • 39
  • 59

1 Answers1

5

I use a common TAG format as follows.

For Activities for example, I have defined a base Activity class...

public class MyCompanyActivity extends Activity {
    protected final String TAG = this.getClass().getName();
    ...
}

All Activities I create extend that Activity, example.

public class FishActivity extends MyCompanyActivity {
    ...
}

The result is that FishActivity will have a TAG which is...

com.mycompany.myapp.FishActivity

All I then need to do is filter the logcat on com.mycompany.myapp

Squonk
  • 48,735
  • 19
  • 103
  • 135
  • Thanks, this approach looks a clean way of doing it, we wouldn't even need to declare TAG variable in every activity, but just wondering is there any side-effect of using this approach? Since you said "I use..." so I guess this should work fine without any catch, right? – Atul Goyal Mar 11 '12 at 20:58
  • @AtulGoyal: I can't think of any side effect and have been using this approach since I started with Android development. I've created base classes for `Application`, `Activity`, `Service` and so on. Because of this I never need to manually define a `TAG` and it is always available and reflects the class name with the unique `package.appname` prefix. I even have users help me debug my app by using something like Catlog and filtering on the company name and emailing me the results. It ensures I only get information related to my apps and nothing else that may infringe user privacy for example. – Squonk Mar 11 '12 at 23:59
  • One more thing, how do you filter the logcat on `com.mycompany.myapp` The logcat command wouldn't work for me when I type `adb logcat com.mycompany.myapp:I *:S` but works for `adb logcat com.mycompany.myapp.FishActivity:I *:S` – Atul Goyal Mar 12 '12 at 06:08
  • I don't use the adb command line, I use the DDMS perspective in Eclipse (available through Window -> Open Perspective -> Other). I specify a filter to match on `com.mycompany.myapp.*` and it works fine. – Squonk Mar 12 '12 at 07:16
  • So, there is no way to get it working outside Eclipse? Actually I'm using this library [ACRA](http://code.google.com/p/acra/) to collect crash data when the application crashes so have to pass the parameters of logcat command there. adb logcat command seems to be not much powerful now :( – Atul Goyal Mar 12 '12 at 07:49
  • Did u try using a regular expression? Like this: adb logcat com.mycompany.myapp.*:I *:S The star at the end of myapp is a regular expression, including any characters. I haven't tried it myself but it might be worth giving it a shot. – AgentKnopf Mar 20 '12 at 08:19