Twitter: raymondcamden

Address: Lafayette, LA, USA

Yet another Cordova/PhoneGap Debugging Tip

07-15-2014 6,426 views Mobile 7 Comments

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
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.


These comments will soon be imported into Disqus. To add a comment, use Disqus above.
  • Sebastian T. #
    Commented on 07-16-2014 at 4:43 PM
    Hi Raymond,

    do you know what is the difference between that and the adb logcat for Android purpose?
  • Commented on 07-16-2014 at 10:04 PM
    Nope, sorry.
  • Commented on 07-20-2014 at 7:42 PM
    Ray, the most useful snippet I found for debugging phonegap is:
    window.onerror = function(msg,url,line){
    console.log('window.onerror :',msg,url,line);
  • Commented on 07-21-2014 at 8:57 AM
    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.
  • Commented on 07-21-2014 at 9:01 AM
    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.
  • Tony OHagan #
    Commented on 08-07-2014 at 11:49 PM
    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 ...
  • Commented on 08-11-2014 at 11:33 PM
    Thank you very much for posting this very useful tip! It came quite in handy in my day work!