Reputation: 22518
I am upgrading an app from PhoneGap 1.9 to PhoneGap 3.0. The console.log() function is not working anymore. Previously, the ouput was written in the XCode console. What's the best way to restore the logging feature?
I have read: PhoneGap 2.0 doesn't show console.log in XCode but in PhoneGap 3.0 console.log does not work even after the deviceReady event.
I am also interested to see the javascript errors directly in xcode.
Upvotes: 21
Views: 29910
Reputation: 469
I found GapDebug really useful. Unlike anything else [cough cough weinre], it let's you console log from your local app
Upvotes: 0
Reputation: 1053
You need the debug console plugin added to your project:
phonegap local plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-console.git
In later versions of phonegap/cordova, to add the debug console plugin in your project:
cordova plugin add org.apache.cordova.console
Upvotes: 31
Reputation: 2946
I've found JSconsole.com extremely useful for remotely capturing console logs from mobile devices.
Heres how you set it up:
In you apps index.html, Include(change the ID):
<script src="http://jsconsole.com/remote.js?<MAKE UP SOME UNIQUE ID>"></script>
:listen <YOUR UNIQUE ID>
Open your app on your mobile device, you will see console logs on your computer.
Upvotes: 9
Reputation: 2336
It turned out, at least in my case, that deviceready
function for the logger was not getting called. The final line in logger.js
.
document.addEventListener("deviceready", logger.__onDeviceReady, false);
The solution (or really a work-around) is to call the logger.__onDeviceReady
function from your deviceready
listener function:
function onDeviceReady() {
if (window.cordova.logger) {
window.cordova.logger.__onDeviceReady();
}
}
document.addEventListener('deviceready', onDeviceReady, false);
Upvotes: 30
Reputation: 4510
Besides adding the Console plugin I have another assumption why it might not work:
console.log in Phonegap is called asynchronously thus if a future call fails, the whole function fails and all log calls within are swallowed.
receivedEvent = function( id ) {
alert( 'This message is displayed because alert is called synchronously ')
console.log( 'This will not be displayed in Phonegap only in browser' )
callingAFunctionWhichDoesNotExist()
console.log( 'This will neither be displayed in Phonegap nor in browser' )
}
Upvotes: 3
Reputation: 314
Problem
The following or a similar error message occurs when adding the console plugin to the ios platform (or after reinstalling) via Command-line Interface:
"CDVPlugin class CDVLogger (pluginName: Console) does not exist."
Solution
Open your Xcode project and go to the tab "Build Phases". Now open the drop-down named "Compile Sources". Click on the "+" sign at the end of the list and add "CDVLogger.m" or any other missing source.
Upvotes: 3
Reputation: 31
If you have installed the Cordova console-plug-in, then when you run your app:
phonegap run iOS
you will find the logs at:
[your project dir]/platforms/ios/cordova/console.log
for IOS. All console logs show up as expected.
Upvotes: 3
Reputation: 361
Add the console plugin as in the Sam's answer and ensure to include cordova.js on every page otherwise no plugin works.
When using phonegap plugins I was adding phonegap.js in script tag then I noticed that plugins (any) works on index.html page only. When I changed phonegap.js to cordova.js, plugins(notification, camera etc) started working on rest of the pages. If this helps anyone.
Upvotes: 6