Alessandro Roaro
Alessandro Roaro

Reputation: 4733

How to filter logcat in Android Studio?

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?

Upvotes: 127

Views: 125659

Answers (11)

Benjamin Mesing
Benjamin Mesing

Reputation: 4334

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.

Upvotes: 12

Josef Vancura
Josef Vancura

Reputation: 1180

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))

Upvotes: 9

live-love
live-love

Reputation: 52494

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

Upvotes: 7

Dawied
Dawied

Reputation: 1117

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.

Upvotes: 2

HostMyBus
HostMyBus

Reputation: 194

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

Upvotes: 12

Suragch
Suragch

Reputation: 512666

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

Upvotes: 2

Ojonugwa Jude Ochalifu
Ojonugwa Jude Ochalifu

Reputation: 27256

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

enter image description here

Upvotes: 3

Gene
Gene

Reputation: 11285

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

Upvotes: 20

James Hackett
James Hackett

Reputation: 1620

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

Upvotes: 124

dmSherazi
dmSherazi

Reputation: 3831

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

Screen Shot

Upvotes: 53

free3dom
free3dom

Reputation: 18988

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

Upvotes: 119

Related Questions