2

I'm using a 3rd party library that currently has some bug that constantly spews out a certain error message in logcat. Sometimes this happens multiple times per second. The text is always the same. This makes debugging really hard as it:

  • makes logcat scroll really fast
  • makes it hard to find relevant logs
  • fills up the whole logfile, deleting older logs (often just a minute old or so)

I assume this is also not good for performance but that's not the real issue.

While waiting for a fix in the library, I would like to filter out this specific error message from logcat. So that I can see everything except this one error and it's stacktrace.

Can I filter this out using Android Studio? If it is filtered, will the messages still get deleted quickly if the file is full?

I know how to disable logs using proguard. I would like to have a solution without proguard since in this development version proguard is disabled.

miva2
  • 2,111
  • 25
  • 34

4 Answers4

6

To filter out unwanted logcat messages in Android-Studio you can use regex negative look-arounds: eg. to filter out all Lines containing zip:

  1. In Logcat-Window click filter-dropdown menu
  2. select "edit Filter Configuration"
    put following code in Log Message field: ^((?!zip).)*$
    and select regex to the right of the field.

I found this way of using regex in the following post: Regular expression to match a line that doesn't contain a word?

rdj7
  • 1,905
  • 4
  • 18
  • 33
kasimir
  • 61
  • 1
  • 4
1

Using adb from the command line you can easily filter out specific tags. I have a script called logcat_filtered that looks like this:

#!/bin/bash
ANDROID_LOG_TAGS='AlarmManager:S daemonapp:S WifiStateMachine:S SensorService:S SignalStrength:S dalvikvm:S Exchange:S ProcessStatsService:S GCoreUlr:S dalvikvm-heap:S chromium:S DMCFaceEngine:S SmartFaceService:S SecCamera-JNI-Cpp:S Camera_HAL:S STATUSBAR-BatteryController:S STATUSBAR-PhoneStatusBar:S STATUSBAR-NetworkController:S Camera:S lights:S BatteryService:S IconMerger:S LockPatternUtils:S' adb logcat

This gets rid of a lot of annoying log output that I'm not interested in.

A simpler solution, again from the command line, is to use grep:

adb logcat | grep -v dontwanttoseethisstring
emidander
  • 2,383
  • 22
  • 29
1

Combining previous two answers with some checking of the documentation gave me a good solution to see the logs that I want.

adb -d logcat -v threadtime | grep -w 4451 | grep -v 4488

-d so I can limit the output to the logs from my currently connected device while I still have emulators running in the background.
-v threadtime So that I can see the Process ID and Thread ID and timestamp.
grep -w 4451 With 4451 being the Process ID. This makes sure I see only logs from my app.
grep -v 4488 With 4488 being the Thread ID of the error message I want to filter out. This removes all lines with the specified Thread ID. This works because in my case the error message only comes in a separate thread.

Now I can see all the logs from my application without all the noise from the error in the library. (Not confirmed but I believe the logs will still disappear when the log file is full because of the constant stream of error messages from the library.)

This is a command line solution, so it is still not an optimal solution using logcat in android studio. But it does perfectly work from the Terminal tab in Android Studio.

miva2
  • 2,111
  • 25
  • 34
0

1- You can add a tag to specific logs when creating them:

Log.i("MyTag", msg);

and in logcat filter them ike this:

Tag:MyTag

2- To filter all logs from only your app filter the logcat by typing :

app:com.example.yourappname

EDIT: Due to the comments:

3- To filter logs created by a thread, at run time find a log that you want to filter same logs. See the TID column and filter the logcat with TID (Thread ID)

Note that every time that your app is run again , you should do this again.

Ahmad Behzadi
  • 1,006
  • 15
  • 30
  • Thanks for your answer but that doesn't help me. The logs are generated by a third party library. I don't want to filter them like that. I want to see every log EXCEPT that one from the library (which is 13 separate lines btw) – miva2 Sep 30 '15 at 12:07
  • May you find the processID or ThreadID at run time and filter it? – Ahmad Behzadi Sep 30 '15 at 12:11
  • That might be interesting. If you could enlighten me on that that would be great! =) – miva2 Sep 30 '15 at 12:27