Writing to the console is an invaluable tool in web development, and many of us keep the console open in Chrome almost indefinitely. Here is how you can get that same functionality in PhoneGap when compiling a native iOS or Android app.

PhoneGap Plugins

Out of the box, PhoneGap doesn’t do much as far as device-level integration. In order to use the phone’s features, you need to add plugins. One such plugin is for console use.

Bash

phonegap local plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-console.git
phonegap build ios

Run this command in the root of your PhoneGap site, and you’ll now have command line access. As usual, compile your app using the build command, and you can now see console.log statements in your platforms when testing compiled apps. These will show up in the following places by platform:

iOS

Log messages show up in the debug panel at the bottom of Xcode.

Android

Log messages show up in the command line tool logcat. This is also bundled into the Android Eclipse plugin.