How to exclude certain messages by TAG name using Android adb logcat?
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
Kostas
Updated on May 07, 2021Comments
-
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 about 13 yearsWell 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 about 11 years@zest
grep
is a standard unix command. For windows you may tryfind /V "notshownmatchpattern"
. P.S. Apparently, the adb shell also has agrep
. But it is not the same as the standard unixgrep
! -
Henadzi Rabkin about 11 yearsYeah, 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 almost 11 yearsThis 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 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 almost 11 yearsGood solution for Eclipse LogCat
-
suomi35 over 10 yearsMy vision is immediately less blurry! :D
-
emidander over 10 yearsYou 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 over 9 yearsNo 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 almost 9 yearsor install clink for common unix commandline tools on windowze
-
ar-g over 8 yearsThis is what I'm looking for quite a while
-
petey about 8 yearsthis answer works in intellij 15's logcat > Edit Filter Configuration which brings up a modal titled, "Create New Logcat Filter" .
-
Atul almost 8 yearsWorked like charm! Many thanks. Add word "dalvikvm" also in it. It's most annoying in logcat.
-
Raghav Satyadev almost 8 years@PCoder can you please write whole command for doing the same with windows CMD?
-
LarsH about 7 yearsThank you, this is very helpful. I also add "jdwp" to the list of excluded words.
-
Ritesh Gune about 7 yearsIMHO,This is more comprehensive way of filtering logs.
-
Seagull almost 7 yearsThank you. Btw Lenovo phones have a lot of spam log messages
-
TheBestBigAl almost 7 yearsThis 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 over 6 yearsAnswer with logcat filtering is the proper one - stackoverflow.com/a/17468665/828237
-
kwesolowski over 6 yearsAnswer with logcat filtering is the proper one - stackoverflow.com/a/17468665/828237
-
Gurupad Mamadapur about 6 yearsSome more :
^(?!(WifiMulticast|WifiHW|MtpService|PushClient|EGL_emulation|OpenGl*|InputReader|art|dalvik|Environment|DataRouter|AlarmManager|WindowManager|PhoneStatusBar|ActivityManager|ResourceType|PackageManager|gralloc*))
-
Vlad over 4 yearsOr if one tag
^(?!tag1)
-
Graeme over 4 yearsAnd more: (Gnss|NetRec|ResolverController|GAv4|AsyncOperation|AppOps|WificondControl|aofp|wifi|netmgr|ctxmgr|BestClock|FirebaseInstanceId|android.os.Debug|memtrack|netd|system_server|StrictMode|bluetooth|NetworkMonitor|FA|BroadcastQueue|ConnextivityService|WakeLock|HttpClientWrapper|RAWR|Tenor|BgTask|WifiService|BluetoothAdapter|UpdateStatsService|AppIdleHistory|Connectivity|VelvetNetworkClient|WorkerManager|EGL_emulation|chatty|gralloc|InputReader|ActivityThread|ActivityTaskManager|UsageStatsService|ocess.gservice|DropBoxManagerService|EventLogChimeraService|PContextMetricsRunner))