124

In my logcat there is too much output, so I'd like to filter it using some keywords, basically displaying only the output containing the keyword(s). Is there a way to do that in Android Studio through the UI?

Alessandro Roaro
  • 4,665
  • 6
  • 29
  • 48
  • possible duplicate of [Filter LogCat to get only the messages from My Application in Android?](http://stackoverflow.com/questions/6854127/filter-logcat-to-get-only-the-messages-from-my-application-in-android) – Ismail Sahin Nov 12 '13 at 14:44
  • no, I'm asking how to filter the messages by keyword. – Alessandro Roaro Nov 16 '13 at 10:59
  • as from android studio ver 0.4.5 you will get messages from the app that is running only. `Log cat has a new option (on by default) which creates an application filter automatically such that only the launched application's output is shown` – dmSherazi Feb 16 '14 at 09:25

11 Answers11

121

What I do is right click on a line I don't like and select "Fold lines like This"enter image description here

James Hackett
  • 1,580
  • 2
  • 13
  • 14
118

There are two ways to do this, both are in the Android tab at the bottom of the IDE (where the logcat output is displayed).

First, you can simply type something into the search box at the top and it should filter only messages containing the text you type.

Second, you can do advanced filtering by clicking on the dropdown at the top right, which should be displaying No Filters by default, and choose Edit Filter Configuration and specifying what to filter on. Using this method you also save the filters and can re-use them by selecting them in the dropdown.

Screenshot:
Search & Filter Logcat

free3dom
  • 18,729
  • 7
  • 52
  • 51
  • 1
    Thanks for you answer. I had already tried the first one, but it doesn't filter out the non-relevant output. Re: the second option, unfortunatly I can't see the dropdown menu, what version are you using? – Alessandro Roaro Nov 14 '13 at 09:35
  • 1
    I am using v0.3.5... added a screenshot of it to the answer. – free3dom Nov 14 '13 at 13:25
  • 1
    I just noticed this while doing the screenshot, there is YET another way to filter. On the **left** side (right next to the tabs) is an icon with green arrows - it can be toggled on/off to display only logcat from the process selected in the list :) – free3dom Nov 14 '13 at 13:31
  • Thank you, I didn't have those filters in my version (0.3.2) – Alessandro Roaro Nov 16 '13 at 11:00
  • No problem! I suppose it was added in v0.3.3/4 then. Android Studio is getting better with each version :) – free3dom Nov 16 '13 at 15:54
  • Omg, I didn't have it in my 0.2.0 version. – Leo Nov 26 '13 at 19:52
  • I only see those buttons when debugging, what if I wanna filter the log while running the app but not debugging it? The search does not help much but to highlight the results. What I want is a filter like the DMS Monitor has. Is it possible to do it from inside Android Studio? (I am using 0.5.8 version) – Chiara May 12 '14 at 07:43
  • Thanks. UI Fail!That needs to be more obvious - a filter textbox needs to be up there - like eclipse – Gishu Dec 22 '14 at 13:37
  • Even though AS now displays only message specifically to the app, so much of the app messages are meaningless. Wish AS was more like Xcode and showed the messages you specify, errors, etc. that was really relevant. I see lots of messages like "Tagging socket 98 with tag 3000110100000000{805310721,0} uid -1, pid: 14922, getuid(): 10005" in AS and I haven't any idea what it is nor why I see such. This sort of stuff I think should be filtered out. Having to actually look/search for messages I put in is troublesome. AS should look how Xcode does it. – Micah Montoya Jan 12 '17 at 12:50
53

As @free3dom said you can select the process from which you want to receive logcats. Here is the screenshot.

Screen Shot

dmSherazi
  • 3,743
  • 5
  • 37
  • 62
  • 2
    Thanks for adding this. It's good to have it here for everyone and I only mentioned it in the comments :) – free3dom Nov 26 '13 at 23:57
  • 41
    Nice graphics too ;-) – Gerard Dec 16 '13 at 21:10
  • 1
    as from android studio ver 0.4.5 u will get messages from the app that is running only. `Log cat has a new option (on by default) which creates an application filter automatically such that only the launched application's output is shown` – dmSherazi Feb 16 '14 at 09:24
  • 1
    +1 for thre press this on 'Only show logs from selected process' – lujop Jul 31 '14 at 21:10
  • I have one another problem, when i apply filter from filter configuration, for a particular package, logcat becomes blank. – Bhupesh Feb 25 '15 at 11:57
20

I MADE A VIDEO TUTORIAL TO SHOW YOU HOW= https://youtu.be/xw2qE5ko_9I

Give your log a name. I called mine "wawa".

enter image description here

In Android Studio, go to Android-> Edit Filter Configurations

enter image description here

Then type in the name you gave the logs. In my case, it's called "wawa". Here are some examples of the types of filters you can do. You can filter by System.out, System.err, Logs, or package names:

enter image description here enter image description here enter image description here

Gene
  • 10,819
  • 1
  • 66
  • 58
  • 2
    Is there a regex to negate this, in order to hide the logs that contain a line? – Hugo M. Zuleta Nov 22 '16 at 18:49
  • Not that I know of. If you want to use regex, I think the best way is to adb into the Android OS and use Grep on the Bash Terminal. – Gene May 18 '18 at 22:50
  • ^(?!chromium)(?!WebViewFactory)(?!zygote) .... add tags like these you want to hide like (?!TAG_NAME). If you want to use regex for a tag, eg. you want to hide all tags starts with "asd", then you add (?!(^asd)) to this "list" of tags. – Drusantia Jun 06 '18 at 12:49
12

First declare your TAG names in your code e.g.

private static final String TAG = "MainTagName";

Then add log statements where you want to output something

Log.d(TAG, "Activity created");

As per free3dom in the second post, on the logcat tab click on the Filters dropdown and then Edit Filter Configuration.

In this example we are using by Log Tag (regex) option to display log messages for any of the three matching tag names using the pipe | separator (without spaces):

MainTagName|SomeTagName|SomeOtherTagName
zehawk
  • 210
  • 1
  • 10
HostMyBus
  • 195
  • 2
  • 9
  • 2
    I don't get any logcat output when using the | to separate the two tags (Android Studio 1.2) – Someone Somewhere May 12 '15 at 18:52
  • 2
    @SomeoneSomewhere Ensure that your TAG's name matches the first parameter in the Log statement. Make sure there are no spaces between the tag names and pipe e.g. tag1|tag2. Be sure that you are in fact hitting the tag command by debugging your code. Check your log level is set to Debug or Verbose in the Log level drop down in the logcat window. – HostMyBus May 15 '15 at 00:05
  • 2
    I tried all kinds of combinations. Mine failed because I had my filter with spaces and the | like "Tag1 | Tag2". Found this answer and removed spaces and it works perfectly. Thanks! – raddevus Feb 15 '16 at 18:49
9

see this https://medium.com/zinuzoid/if-you-developing-android-application-1bdff0a96205

just create LogCat filter a insert below String to "LogTag" which will then ignore system lines

^(?!.*(BtGatt|dalvik|Environment|DataRouter|FA|art|Wifi|ServiceManager|Atfwd|tnet|MDnsDS|Download|Bluetooth|slim|QSEECOMAPI|WVCdm|QC-time|sensors|nanohub|Drm|Babel|Dropbox|gsamlab|Cryptd|Vold|QC_|Conscrypt|Dns|sound|NetWork|OpenGL|TLog|GMPM|Microphone|Process|Dynamite|cr_|VideoCapabilities|libEGL))
Josef Vancura
  • 1,053
  • 10
  • 18
9

With AndroidStudio Dolphin a new logcat view mode was introduced providing a more structured view of the logcat output. It also introduced the new filtering options package:, tag: and level:. You can also search for the text in the whole entry by not preceding an option.

Example filter

Quoting from Googles News post where the new logcat was introduced (https://androidstudio.googleblog.com/2022/03/android-studio-dolphin-canary-6-now.html) [Update] Proper Documentation is now available here https://developer.android.com/studio/debug/logcat

Specific values:

  • package:<my-package-ID>
  • tag:<my-tag>
  • level:[VERBOSE | INFO | ASSERT | DEBUG | WARN | ERROR]

Exclude a specific value by preceding the key with -:

  • -tag:<exclude-this-tag>

Use the regular expressions with a given key by placing a ~ after the key:

  • tag~:<regular-expression-tag>

Combine with the exclude tag:

  • -tag~:<exclude-this-regex-tag>

You can also see a history of queries by clicking the filter icon in the query field and selecting them from the drop down. To favorite a query so that it stays at the top of the list across all your studio projects, click the star icon at the end of the query field.

package:mine matches all PIDs for the local app project.

Benjamin Mesing
  • 4,075
  • 1
  • 18
  • 22
7

I had trouble turning on the filters in Logcat. To see the filters in Android Studio 3.2, you have to toggle 'Floating Mode' on and off again to make the filters reappear.

enter image description here

Pang
  • 9,564
  • 146
  • 81
  • 122
live-love
  • 48,840
  • 22
  • 240
  • 204
3

One alternative that works for me is to select the Show only selected application option in the filter menu:

enter image description here

Ojonugwa Jude Ochalifu
  • 26,627
  • 26
  • 120
  • 132
2

I don't know if the images in the other answer are old or if I was missing something, but here is an updated image.

Click the Android Monitor tab at the bottom and make sure the logcat tab is selected. Then type in whatever you want to filter your output. I filtered mine with my tag name TAG.

enter image description here

Suragch
  • 484,302
  • 314
  • 1,365
  • 1,393
2

Just to add my own mistake:

make sure that when you are using the Emulator and a real device, to switch to the device you are debugging in the dropdown on the left above the logcat tab.

Dawied
  • 897
  • 10
  • 16