How to view console.log() in the emulator?

I’m building an app using Ionic, which I’ve done in the browser until now. Because I now want to use the cordovaOauth plugin I need to use the emulator. The problem is that I can’t see any console.log() in the emulator as I do in the browser, which makes it hard to debug.

Does anybody know how I can make use of console logging in the emulator? All tips are welcome!

2 Likes

Which emulator? iOS or Android?

@kramer65 You can use the plugin gapDebug available for iOS and Android. It is very easy to take and free.

gapDebug

1 Like

The Cordova Device Plugin comes pre-installed. To view logs for iOS just launch the emulator in xcode and the log will show up within Xcode. If you launch it from within terminal cordova outputs a console.log file you can open and view. For android launch it with eclipse or Android App Studio and you can look at the log with LogCat.

I like to inspect the browser windows. Very easy actually: for Android fire up chrome and enter “chrome://inspect”.
For IOS open your safari and in the developer tools it should say something like “Emulation” or “Inspect” as well.

8 Likes

Combine this and logcat for the best solution. The chrome dev tools just tell you about the DOM renderings, sometimes Logcat can provide valuable verbose information about plugins not loading or something.

It should work by adding --consolelog or -c , right?
Unfortunately it does not work for me on both the iOS and the Android emulator.
So when I run:
ionic emulate ios -c
I expect console.log messages to be visible in my terminal.
How convenient would that be, instead of hooking up the safari debugger every time?
Well it does not seem to work.
Does anyone know an actually solution for that?
Update: on the Android emulator it seems to work

1 Like

ionic emulate ios --lc
ionic emulate android --lc

7 Likes

Thank you!!! I’ve been trying to find this answer for several days now. You’re the first to drive it home for me.

I was also trying to find the similar solution with Genymotion.

After scrapping web a bit, I found it can be done easily and any WebApp Console.log() can be viewed from logcat.

Launch you application with genymotion or any emulator.
Execute adb devices to see all the devices
i had below devices in output of adb devices
List of devices attached
192.168.56.101:5555 device
To get output log use :
adb -s 192.168.198.101:5555 logcat

Reference
[1] https://stackoverflow.com/questions/6203240/how-to-run-logcat-on-multiple-devices
[2] https://developer.android.com/guide/webapps/debugging