How to filter out a tagname in Eclipse LogCat viewer

I have an Android application that "spams" the LogCat and I would like to remove its logcat entries in order to have an output more readable.

Is it possible to have a filter that remove the LogCat entries for a specific tag name? Or a search pattern that does the trick?

33094 次浏览

Depends on which way you view your logcat.

If you are using the GUI logcat interface it's best to create a filter for the tags you want to see. These get dropped into a seperate category. Though the ui changed a bit you can use this old answer from me. Should be clear how this is used (make sure that the "display saved filters tab" button is pressed though, otherwise you won't see the "Add filter" button. You can find that on the top-right of the log). I'm not aware of any option that lets you filter out certain tags from the whole logstream.

If you are using the command line you can mute certain tags. Example:

adb logcat AndroidRuntime:S *:V

shows everything (*:V) up to the verbose log level, except the tag AndroidRuntime, which will be limited to the "silence" loglevel, which means it will print nothing.

To display a single tag you can use

adb logcat *:S MyAppTag:V OtherTag:V

Same way, everything gets silenced except MyAppTag and OtherTag. See Filtering Log Output for more details.

I have a trick:

 Log.d(TAG, "MyTag" + message);

As you can see, when I filter with a key "MyTag", it only shows log from my tag.

Yes. Create a filter where the "By log tag" field is

^(?!.*(MYTAG)).*$

where MYTAG is the tag you don't want to see. I am not a regexp expert (a "regexpert"? ;-) ) so there may be a simpler way to do that negation, but I just tried that and it works.

You can play around with the filter in the field just above the Log Cat message area, by entering filter strings there, like this:

tag:^(?!.*(DeskClock|dalvik|wpa)).*$

which will show all messages except tags "DeskClock", "dalvik", and "wpa".

This is a late response, but maybe useful. In the Eclipse environment, in the LogCat view, above the table there is a search box. Pay attention, when empty it reads:

Search for messages. Accepts Java regexes. Prefix with pid:, app:, tag: or text: to limit scope.

It means you can filter your tag by writing there tag:MyTag or even regex tag:My.*

This might not seem directly relevant to the question but here is a regex which filters out most of the system generated logs when you put this in your tag filter as described by Rob.

^(?!(WifiMulticast|WifiHW|MtpService|PushClient|InputMethodManager|Provider|SurfaceTextureClient|ImageLoader|dalvikvm|OpenGLRenderer|skia|AbsListView|MediaPlayer|AudioManager|VelocityTracker|Drv|Jpeg|CdpDrv|IspDrv|TpipeDrv|iio|ImgScaler|IMG_MMU|ResMgrDrv|JpgDecComp|JpgDecPipe|mHalJpgDec|PipeMgrDrv|mHalJpgParser|jdwp|libEGL|Zygote|Trace|InputEventReceiver|SpannableStringBuilder|IInputConnectionWrapper|MotionRecognitionManager|Choreographer|v_galz|SensorManager|Sensors|GC|LockPatternUtils|SignalStrength|STATUSBAR-BatteryController|BatteryService|STATUSBAR-PhoneStatusBar|WifiP2pStateTracker|Watchdog|AlarmManager|BatteryStatsImpl|STATUSBAR-Clock))

I keep updating this list of tags as i encounter them testing on different devices. The list is not exhaustive and you are free to contribute to this answer. I am sure this will save an hour for many.

If there are other other logs you need filtered out, append them to this regex using a ' | ' character.

I couldn't get chosen solution to work properly in Android Studio (the IDE that will come with future versions of android SDK). However the following regex solved my problem:

^(?!dalvikvm)

Another way to filter out log messages that don't originate from YOUR app is to select:

Log Level: Verbose

"Show only selected application" (from the filter selection drop down)

Then select your application from the from the drop down debuggable list in the logcat window.

This should only show log messages and output from your app.