Twitter: raymondcamden


Address: Lafayette, LA, USA

Yet another Cordova/PhoneGap Debugging Tip

07-15-2014 3,405 views Mobile 5 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.

5 Comments

  • 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');
    doX();
    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.

Post Reply

Please refrain from posting large blocks of code as a comment. Use Pastebin or Gists instead. Text wrapped in asterisks (*) will be bold and text wrapped in underscores (_) will be italicized.

Leave this field empty