How to filter logcat in Android Studio?
Asked Answered
F

11

126

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?

Frankforter answered 12/11, 2013 at 14:34 Comment(3)
possible duplicate of Filter LogCat to get only the messages from My Application in Android?Diastasis
no, I'm asking how to filter the messages by keyword.Frankforter
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 shownEcto
V
119

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

Valeriavalerian answered 13/11, 2013 at 8:12 Comment(9)
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?Frankforter
I am using v0.3.5... added a screenshot of it to the answer.Valeriavalerian
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 :)Valeriavalerian
Thank you, I didn't have those filters in my version (0.3.2)Frankforter
No problem! I suppose it was added in v0.3.3/4 then. Android Studio is getting better with each version :)Valeriavalerian
Omg, I didn't have it in my 0.2.0 version.Eidetic
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)Blinker
Thanks. UI Fail!That needs to be more obvious - a filter textbox needs to be up there - like eclipseHusband
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.Work
P
122

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

Poetize answered 7/11, 2015 at 17:47 Comment(5)
how can this step be reverted? I did it by accident :-/Szechwan
ok got it :-D (just double click on green colored entry with text: "n internal calls")Szechwan
@Aydin K. This can be reverted by selecting the pattern and pressing the "-" button.Cloudburst
way easier than writing regexes in filter configuration !Disown
For me, this produces lots of "I/chatty ... identical N lines". I solved that problem by adding a filter config which filters by logtag regex: ^(?!.*chatty).*$ and by my package nameThorp
V
119

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

Valeriavalerian answered 13/11, 2013 at 8:12 Comment(9)
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?Frankforter
I am using v0.3.5... added a screenshot of it to the answer.Valeriavalerian
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 :)Valeriavalerian
Thank you, I didn't have those filters in my version (0.3.2)Frankforter
No problem! I suppose it was added in v0.3.3/4 then. Android Studio is getting better with each version :)Valeriavalerian
Omg, I didn't have it in my 0.2.0 version.Eidetic
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)Blinker
Thanks. UI Fail!That needs to be more obvious - a filter textbox needs to be up there - like eclipseHusband
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.Work
E
53

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

Screen Shot

Ecto answered 17/11, 2013 at 7:34 Comment(5)
Thanks for adding this. It's good to have it here for everyone and I only mentioned it in the comments :)Valeriavalerian
Nice graphics too ;-)Licko
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 shownEcto
+1 for thre press this on 'Only show logs from selected process'Plump
I have one another problem, when i apply filter from filter configuration, for a particular package, logcat becomes blank.Disorganization
R
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

Rida answered 20/4, 2015 at 19:46 Comment(3)
Is there a regex to negate this, in order to hide the logs that contain a line?Calibrate
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.Rida
^(?!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.Cykana
B
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
Briar answered 8/3, 2015 at 12:33 Comment(3)
I don't get any logcat output when using the | to separate the two tags (Android Studio 1.2)Plater
@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.Briar
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!Symmetrical
P
12

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.

Priesthood answered 3/11, 2022 at 15:2 Comment(0)
T
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))
Tova answered 5/2, 2020 at 9:32 Comment(1)
Regex does not work anymore. Use -tag:UnWantedTag to exclude a tag instead. Use several to exclude more.Monochrome
S
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

Scarletscarlett answered 22/11, 2018 at 19:2 Comment(0)
L
3

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

enter image description here

Lasonyalasorella answered 25/10, 2016 at 17:17 Comment(3)
Any idea when the "Firebase" option arrived? I saw it for the first time today (after spending an age wondering why my app was no longer logging).Collen
I had no idea it was even there.Lasonyalasorella
Neither did I, but I had selected it (without knowing) and that wasted a lot of time. Thx anywayCollen
W
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

Whelm answered 2/12, 2016 at 10:22 Comment(0)
V
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.

Visitation answered 16/12, 2017 at 10:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.