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

57,932

Solution 1

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.

Solution 2

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.

Solution 3

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

Solution 4

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"

Solution 5

^(?!.*(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

Share:
57,932
Kostas
Author by

Kostas

Updated on May 07, 2021

Comments

  • Kostas
    Kostas about 3 years

    Logcat allows filtering logs but it works like that: You define filters and logcat only displays messages which matches filters. But is there a way to display all logs EXCEPT some TAGs defined by filters?

  • Kostas
    Kostas about 13 years
    Well I forgot to mention that I am using that on command prompt / inside a phone to read logs. And each time I tap a screen it shows InputReader / InputDispatcher messages which are just flooding the screen. Now I see also setting filters to "InputReader:S InputDispatcher:S" works :) Thanks for an answer!
  • PCoder
    PCoder about 11 years
    @zest grep is a standard unix command. For windows you may try find /V "notshownmatchpattern". P.S. Apparently, the adb shell also has a grep. But it is not the same as the standard unix grep!
  • Henadzi Rabkin
    Henadzi Rabkin about 11 years
    Yeah, I found it already, findstr - suck, possible to install powershell or grep (for windows:), the same as Linux as was wrote in readme, but not so much in practice)
  • Chris Markle
    Chris Markle almost 11 years
    This is a good suggestion and works from the command line with no pipelines. You should update your answer imho to explain that the ":S" part is going to only emit Severe messages for the named components (which hardly ever happen). Again, good answer. People should vote up this one...
  • Rich
    Rich almost 11 years
    @ChrisMarkle According to the docs the S is for 'silent'. I've updated the answer to explain this though, as you suggest.
  • Seraphim's
    Seraphim's almost 11 years
    Good solution for Eclipse LogCat
  • suomi35
    suomi35 over 10 years
    My vision is immediately less blurry! :D
  • emidander
    emidander over 10 years
    You can filter logcat output in the same way using the environment variable ANDROID_LOG_TAGS. I find it useful to have it always set to exclude some of the more spammy processes.
  • chris polzer
    chris polzer over 9 years
    No adays, I would just adivce for windows to install git with git commandline tools. This would install all basic unix commandline tools for windowze.
  • chris polzer
    chris polzer almost 9 years
    or install clink for common unix commandline tools on windowze
  • ar-g
    ar-g over 8 years
    This is what I'm looking for quite a while
  • petey
    petey about 8 years
    this answer works in intellij 15's logcat > Edit Filter Configuration which brings up a modal titled, "Create New Logcat Filter" .
  • Atul
    Atul almost 8 years
    Worked like charm! Many thanks. Add word "dalvikvm" also in it. It's most annoying in logcat.
  • Raghav Satyadev
    Raghav Satyadev almost 8 years
    @PCoder can you please write whole command for doing the same with windows CMD?
  • LarsH
    LarsH about 7 years
    Thank you, this is very helpful. I also add "jdwp" to the list of excluded words.
  • Ritesh Gune
    Ritesh Gune about 7 years
    IMHO,This is more comprehensive way of filtering logs.
  • Seagull
    Seagull almost 7 years
    Thank you. Btw Lenovo phones have a lot of spam log messages
  • TheBestBigAl
    TheBestBigAl almost 7 years
    This only prevents logs with that tag from being rendered to the log though. Monitor still gets swamped with those calls in the background and it pushes the non "tag1|tag2|etc" calls out of the buffer. Is there a way around that?
  • kwesolowski
    kwesolowski over 6 years
    Answer with logcat filtering is the proper one - stackoverflow.com/a/17468665/828237
  • kwesolowski
    kwesolowski over 6 years
    Answer with logcat filtering is the proper one - stackoverflow.com/a/17468665/828237
  • Gurupad Mamadapur
    Gurupad Mamadapur about 6 years
    Some more : ^(?!(WifiMulticast|WifiHW|MtpService|PushClient|EGL_emulatio‌​n|OpenGl*|InputReade‌​r|art|dalvik|Environ‌​ment|DataRouter|Alar‌​mManager|WindowManag‌​er|PhoneStatusBar|Ac‌​tivityManager|Resour‌​ceType|PackageManage‌​r|gralloc*))
  • Vlad
    Vlad over 4 years
    Or if one tag ^(?!tag1)
  • Graeme
    Graeme over 4 years
    And more: (Gnss|NetRec|ResolverController|GAv4|AsyncOperation|AppOps|W‌​ificondControl|aofp|‌​wifi|netmgr|ctxmgr|B‌​estClock|FirebaseIns‌​tanceId|android.os.D‌​ebug|memtrack|netd|s‌​ystem_server|StrictM‌​ode|bluetooth|Networ‌​kMonitor|FA|Broadcas‌​tQueue|ConnextivityS‌​ervice|WakeLock|Http‌​ClientWrapper|RAWR|T‌​enor|BgTask|WifiServ‌​ice|BluetoothAdapter‌​|UpdateStatsService|‌​AppIdleHistory|Conne‌​ctivity|VelvetNetwor‌​kClient|WorkerManage‌​r|EGL_emulation|chat‌​ty|gralloc|InputRead‌​er|ActivityThread|Ac‌​tivityTaskManager|Us‌​ageStatsService|oces‌​s.gservice|DropBoxMa‌​nagerService|EventLo‌​gChimeraService|PCon‌​textMetricsRunner))