Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to exclude certain messages by TAG name using Android adb logcat?

People also ask

What is Logcat in ADB?

Logcat is a command-line tool that dumps a log of system messages, including stack traces when the device throws an error and messages that you have written from your app with the Log class. This page is about the command-line logcat tool, but you can also view log messages from the Logcat window in Android Studio.

How do I end ADB Logcat?

Using -d option will get you a one-time run of logcat. The command above is to clean the logs in logcat buffer. Show activity on this post. -c Clears (flushes) the entire log and exits.


You can do this from within DDMS Monitor (and also Eclipse or Android Studio) with the regular expression input box and negative look-ahead assertions, for example I am excluding a lot of noise from my log with the following:

tag:^(?!(WifiMulticast|WifiHW|MtpService|PushClient))

(The "tag:" isn't part of the regular expression, but tells LogCat to only apply the regex to the Tag field. If you use this trick in a saved filter then put just the regular expression in the "Tag" input box, and omit the "tag:" prefix)

In Android Studio's logcat monitor pane, you can set up a saved filter for this by opening the dropdown in the upper right (it may have "Show only selected application" selected) and selecting Edit Filter Configuration. Create a new logcat filter and put ^(?!(WifiMulticast ...etc. )) in the Log Tag box, with the Regex checkbox checked.


If you want to exclude or filter certain messages by tag name in Android studio, goto the LogCat window=>Edit Filter configuration, and enter the following under "by Log Tag(regex): "

^(?!(tag1|tag2|tag3|tag4))

Note that there are no spaces, this is important


If you are using adb logcat you could pipe it through grep and use it's inverted matching: From the grep manpage:

v, --invert-match Invert the sense of matching, to select non-matching lines.

For example:

$adb logcat | grep --invert-match 'notshownmatchpattern' 

You can extend this by using regular expressions.

Here is an example of such an expression:

"/^(?:emails|tags|addresses)"

This one would check for either of the given to occur, grep would then not list them.


From the shell, you can use a command like:

adb logcat AlarmManagerService:S PowerManagerService:S *:V

which will include all logs apart from those with the AlarmManagerService and PowerManagerService tags.

(The :S stands for "silent", which means nothing will be printed for those tags; the :V stands for "verbose" which means everything will be printed for all other tags. The Android documentation for logcat has more details of other options you can use in the filters.)

You can also use the ANDROID_LOG_TAGS environment variable to set up default filters, e.g. (in bash):

export ANDROID_LOG_TAGS="AlarmManagerService:S PowerManagerService:S *:V"

^(?!.*(WindowManager|dalvik|Environment|DataRouter|AlarmManager)).*$

This will exclude texts having contents WindowManager,dalvik,...

tag:^(?!.*(WindowManager|dalvik|Environment|DataRouter|AlarmManager)).*$

This will exclude tags WindowManager,dalvik,... from logcat


Combine both positive and negative lookahead for more powerful filtering.

Example:

(?=(AndroidRuntime|Main|RandomTag))(?!(Audio))

Tags in the first nested parentheses are included.

Tags in second are excluded.


There is also the option to make your own filter in Android Studios logcat GUI. E.g. I was very annoyed by OpenGLRenderer and ViewRoot messages in logcat.

In the logcat click on Edit Filter Configuration and create a new filter. In the Log Tag Input you can type in something like ^(?!.*(OpenGLRenderer|ViewRoot)) and add several other Tags that are annoying you.

Filter for logcat