activity
activity

Reputation: 2733

LogCat filtering - include and exclude at the same time

I'd like to show logs that contain MainActivity but don't contain ActivityManager, so that this match is excluded:

I/ActivityManager: Start proc 2666:com.example.app/u0000 for activity {com.example.app/com.example.app.MainActivity}

I tried as suggested here:

(?=(MainActivity))(?!(ActivityManager))

But it didn't work.

Upvotes: 0

Views: 1047

Answers (2)

LarsH
LarsH

Reputation: 27996

Nowadays you can use keys to more surgically filter the logcat results. For the example you gave, you want to show log lines whose message contains MainActivity, and whose tag does not contain ActivityManager. So you can set the logcat filters to:

message:MainActivity -tag:ActivityManager

You could get very detailed with regexps and negative lookahead, but there is no longer as much need for that as there used to be.

Be careful though of how you combine these filters. There are implicit logical operators which could be AND or OR, depending on what the Logcat window thinks you mean. In other words, the interpretation is typically right, but can sometimes surprise you, unless you make your operators explicit:

message:MainActivity & -tag:ActivityManager

Upvotes: 0

The fourth bird
The fourth bird

Reputation: 163207

You could make use of a single negative l lookaheadand, use an anchor ^ at the start of the string.

^(?!.*\bActivityManager\b).*\bMainActivity\b.*

That will match

  • ^ Start of string
  • (?!.*\bActivityManager\b) Negative lookahead, assert that ActivityManager is not present
  • .*\bMainActivity\b.* Match the whole line with bMainActivity

Regex demo

Upvotes: 2

Related Questions