13

There are several questions about the subject, however not one of them seems to address the particular problem I'm having.

I'm developing an app with Cordova/Ionic, and printing debugging info I was outputting with console.log() by using adb logcat CordovaLog:D *:S was working just fine until some updates. Now I can't seem to figure out how to properly filter logcat's output so I could only get the debugging info from my app.

Logging itself works. If I set no filters and redirect output to a file, I can see my debugging info among all the other debug messages, and it looks like this:

I/Web Console: Event triggered: device.ready:1

Logging to screen also works, but at a rate of approximately 100 lines per second. I've tried at least the following to filter output:

adb logcat -s "Web Console"
adb logcat "Web Console":V
adb logcat "Web Console":*
adb logcat -s Web
adb logcat Web:V
adb logcat "myApp":V
adb logcat myApp:V
adb logcat -s myApp

... and probably others I've already forgotten. They either print absolutely nothing, or absolutely everything from the system services.

I'm on Windows so I can't grep, and the device I'm debugging on is running Android 4.2.2 so I can't use GapDebug, and neither does it seem to be possible to access the device's log via chrome://inspect in Chrome.

I really, really would like to understand how filtering logcat's output works. I'm not willing to log everything to a file and then shift through that.

Schlaus
  • 18,144
  • 10
  • 36
  • 64
  • 1
    `adb logcat -s "Web Console":*`... I'd recommend not to use spaces in the tag name though – Alex P. May 14 '15 at 21:28
  • @AlexP. nope, still nada. The tag is defined by Cordova, and I have no idea how to change that. It used to be CordovaLog and like I said then everything worked beautifully. Either the info on how to change the tag name doesn't exist in the docs, or my Google Fu fails me miserably. – Schlaus May 14 '15 at 21:49
  • 1
    `adb shell "logcat -s 'Web Console':*"` – Alex P. May 14 '15 at 22:30
  • @AlexP. Thanks, but still the same result. :( Absolutely no output. Perhaps the tag really can't have a space in it. – Schlaus May 14 '15 at 22:33
  • 2
    well there's always `adb shell "logcat | grep 'Web Console'"` – Alex P. May 14 '15 at 22:38
  • 1
    @AlexP. Yes! That's the one! Please make an answer out of it so I can accept it! – Schlaus May 14 '15 at 22:41

4 Answers4

21

It seems that logcat can not properly parse tag names with whitespaces. So instead I suggest using grep on the device:

adb shell "logcat | grep 'Web Console'"
Alex P.
  • 30,437
  • 17
  • 118
  • 169
7

Alternatively when runing adb on linux or unix based os/git bash:

adb logcat | grep 'Web Console'
Dimitrios Desyllas
  • 9,082
  • 15
  • 74
  • 164
5

What works for me in 2019:

adb -d logcat chromium:I *:S

The -d indicating a physical device in my case. If all else fails just dump the results of adb logcat into a text file and do a search for "CONSOLE", that will give you the provider for your logcat filter. It seems this changes over time, and depending on your particular dev environment.

Ben Brian
  • 220
  • 3
  • 6
2

While you can use grep under Linux/Unix, findstr might be your choice under Windows:

adb logcat | findstr /C:"Web Console"

If you prefer to use grep under Windows, you can get it from http://gnuwin32.sourceforge.net/packages/grep.htm.

ingenuine
  • 179
  • 7
  • the accepted answer works the same in all 3 supported operating systems. no need for windows only solution – Alex P. Mar 25 '17 at 05:23
  • You are absolutely right (grep works on all major OS) - I postet this answer a) to target users that are not too familiar with the GNU tools b) to take into account that the user stated "I'm on Windows so I can't grep" and c) to provide a link to grep (once more to target users that mostly work under windows and might not even know of grep) – ingenuine Mar 25 '17 at 10:08
  • 1
    you are missing the point that in the accepted answer `grep` runs on the device itself. so it does not matter if `grep` is available on the host PC system – Alex P. Mar 25 '17 at 13:47
  • I did indeed - very good point - your answer could also improve the performance of the logging if you run the application on a physical device as the host running adb will not have to filter the whole log (leaving it to the device to do the filtering) – ingenuine Mar 26 '17 at 09:57