Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging a WebView (Ionic) app on Android via logcat

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.

like image 702
Schlaus Avatar asked May 14 '15 21:05

Schlaus


People also ask

How do I debug an Ionic app on Android?

Hover over the app name and click on localhost. This will open a new window with the Safari Developer Tools - use them to inspect and debug the Ionic app running on your device.

Does Ionic run in Webview?

Ionic apps are built using web technologies and are rendered using Web Views, which are a full screen and full-powered web browser.

How do you debug an Ionic reaction?

You can use remote debugging with an actual device or simulator. If you use a real device, ensure that debugging is enabled both from the device and on the remote browser. In Android, you need to go to the settings and enable developer mode first and then USB Debugging under the developer options menu.


4 Answers

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'"
like image 159
Alex P. Avatar answered Oct 20 '22 21:10

Alex P.


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.

like image 32
Ben Brian Avatar answered Oct 20 '22 22:10

Ben Brian


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

adb logcat | grep 'Web Console'
like image 7
Dimitrios Desyllas Avatar answered Oct 20 '22 22:10

Dimitrios Desyllas


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.

like image 2
ingenuine Avatar answered Oct 20 '22 20:10

ingenuine