Yet another Cordova/PhoneGap Debugging Tip

This post is more than 2 years old.

Want another way to debug Cordova/PhoneGap apps? This isn't new, but I tend to forget about this option and it came in handy yesterday so I thought I would share. When you send builds to the simulator/device via the command line, you may notice that at the end of all the output about building this and generating that, you get these two lines:

2014-07-14 17:23:36.846 ios-sim[1335:507] stderrPath: /Users/ray/readtextfile/platforms/ios/cordova/console.log<br/> 2014-07-14 17:23:36.847 ios-sim[1335:507] stdoutPath: /Users/ray/readtextfile/platforms/ios/cordova/console.log

What this is telling you is that you have a log file that will report on errors from your application. This also includes console.log output. (As well as console.dir.) If you simply tail -f this file in another terminal tab (and yes, you get tail -f in Windows too with the right download), you get your console output as plain text right in your terminal. Here is an example from what I was working on yesterday.

Edit on July 16: As just an FYI, when I just tested this on a new app this morning, it did not work. I had to add the Console plugin. My initial test was with a Ionic app where this was added automatically.

Raymond Camden's Picture

About Raymond Camden

Raymond is a senior developer evangelist for Adobe. He focuses on document services, JavaScript, and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA

Archived Comments

Comment 1 by Sebastian T. posted on 7/17/2014 at 1:43 AM

Hi Raymond,

do you know what is the difference between that and the adb logcat for Android purpose?

Comment 2 by Raymond Camden posted on 7/17/2014 at 7:04 AM

Nope, sorry.

Comment 3 by Steven Benjamin posted on 7/21/2014 at 4:42 AM

Ray, the most useful snippet I found for debugging phonegap is:
window.onerror = function(msg,url,line){
console.log('window.onerror :',msg,url,line);

Comment 4 by Raymond Camden posted on 7/21/2014 at 5:57 PM

Nice one. If you do use remote debugging, errors show up in the console already, but this would work for the log based console.

Actually - let me confirm errors don't automatically log.

Comment 5 by Raymond Camden posted on 7/21/2014 at 6:01 PM

Ok, so yes, errors are NOT reported to the console log. As an interesting side note, in my first test I added an error to the event handler run by deviceready. I had,

console.log('pre bug');
console.log('post bug');

I assumed I'd see pre bug, and MAYBE an error. But I saw *nothing*. I had to move my code to another function called after the event handler to confirm what I found above.

So it seems like if something goes wrong in the eventhandler for deviceready, nothing is logged. May be worth my time to blog that just as an FYI.

Comment 6 by Tony OHagan posted on 8/8/2014 at 8:49 AM

The latest PG Developer App includes a feature to remotely log calls to console.log()/.warn()/.error() etc to the 'phonegap serve' server via .

I had some pain getting this to install on Windows as you need a version of Visual Studio installed to make work. Here's one place that I posted some help with this ...

Comment 7 by Slava Kim posted on 8/12/2014 at 8:33 AM

Thank you very much for posting this very useful tip! It came quite in handy in my day work!